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

Save time-dependent solution using XDMFFile

0 votes

Hi all,
what is the best way to export a time-dependant solution (in the cpp interface) using the XDMFFile class?. Actually i'm exporting the solution using the next lines:

... previous declarations ...

XDMFFile sol(mesh.mpi_comm(), "xdmf/sol.xdmf");

// Start time stepping
while (t < T)
{
  // Update for next time step
  t += dt;
  std::cout << "Time: " << t << std::endl;

  // Solve problem 1
  Solver1.solve();

  // Save solutions to file
  const std::pair<const Function*, double> ut(&u, t);
  sol << ut;
}

where u is the solution (Function) in each time-step and t (double) the current time.

it's possible doing the same but without to create an std::pair object in each time-step?. If the answer is positive, how can i do it?

Thanks in advance!

asked Jan 18, 2016 by hernan_mella FEniCS Expert (19,460 points)
edited Jan 18, 2016 by hernan_mella

If i move the line const std::pair<const Function*, double> ut(&u, t); outside the loop only the solution of the last time-step is saved.

1 Answer

+2 votes
 
Best answer

I don't think making a pair is very costly (the first member is a pointer). Anyway, I suppose you should remove const and then you can set the values using ut.first and ut.second inside the loop. Probably.

answered Jan 19, 2016 by chris_richardson FEniCS Expert (31,740 points)
selected Jan 19, 2016 by hernan_mella

That was precisely my question, thanks!

...