ste-dtst / nmpde-project

Project for the course Numerical Methods for PDEs, held in University of Pisa by prof. Luca Heltai in 2024.
GNU Lesser General Public License v2.1
0 stars 0 forks source link

Fix problem with PVD file. #3

Closed luca-heltai closed 2 weeks ago

luca-heltai commented 4 weeks ago

Initializing the solution vector with VectorTools::interpolate seems to generate an invalid solution-000.vtu file, which also makes Paraview unable to open the .pvd record. How is this possible?

ste-dtst commented 3 weeks ago

Update: after introducing the ParameterHandler, the solution files are now ok. Only the .pvd issue is still present.

luca-heltai commented 2 weeks ago
--- a/source/project.cc
+++ b/source/project.cc
@@ -458,15 +458,18 @@ HeatEquation<dim>::output_results(const Vector<double> &sol,

   data_out.build_patches();

-  const std::string filename = "output_" + std::to_string(dim) + "d/solution-" +
-                               Utilities::int_to_string(step_no, 3) + ".vtu";
-  std::ofstream output(filename);
+  const std::string dirname = "output_" + std::to_string(dim) + "d/";
+
+  const std::string filename =
+    "solution-" + Utilities::int_to_string(step_no, 3) + ".vtu";
+
+  std::ofstream output(dirname + filename);
   data_out.write_vtu(output);

   static std::vector<std::pair<double, std::string>> times_and_names;
   times_and_names.push_back({step_no, filename});

-  std::ofstream pvd_output("output_" + std::to_string(dim) + "d/solution.pvd");
+  std::ofstream pvd_output(dirname + "solution.pvd");

   DataOutBase::write_pvd_record(pvd_output, times_and_names);
 }
luca-heltai commented 2 weeks ago

The above changes should fix this. The pvd file uses relative paths. If you write in the same output directory of the .vtu files, then you need to write relative paths.

The changes above should fix this.

ste-dtst commented 2 weeks ago

Thanks a lot! This solved the problem.