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

How overwrite file in next timestep.

+1 vote

HI. I have this code on c++.

File file("poisson.vtu");
while (t <= te) 
{
  solve(a==L, u, bcs); 
  file << u;
  u0 = u;
  t = t + dt;  
}

In each iteration fenics create new file poisson_p0_000000.vtu, poisson_p0_000001.vtu and etc. How i can overwrite poisson_p0_000000.vtu in each step and don't create new files?

asked Sep 10, 2013 by Sheva FEniCS Novice (910 points)

2 Answers

+3 votes
 
Best answer

What about

while (t <= te) 
{
  solve(a==L, u, bcs); 
  File file("poisson.vtu");
  file << u;
  u0 = u;
  t = t + dt;  
}
answered Sep 10, 2013 by Jan Blechta FEniCS Expert (51,420 points)
selected Sep 10, 2013 by Sheva
Append output to existing vtk file
+1 vote

As Jan pointed out below, if you instantiate the File object within the loop it will overwrite the file rather than write a new file with an index to it. At the end of the while block the instance will dispose so you can create another.

// File file("poisson.vtu");
while (t <= te) 
{
  solve(a==L, u, bcs); 

  // fresh instance of file
  File file("poisson.vtu");

  file << u;
  u0 = u;
  t = t + dt;  
}
answered Sep 10, 2013 by Charles FEniCS User (4,220 points)
...