]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Check whether the output directory exists. 12080/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Thu, 22 Apr 2021 14:06:58 +0000 (08:06 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 4 Jul 2023 04:50:00 +0000 (22:50 -0600)
examples/step-70/step-70.cc

index 011964a3e1f14989bad6b9a13638ad21f9657d14..720055aa72300a3957a59a0502d97ce067433f2c 100644 (file)
@@ -144,6 +144,7 @@ namespace LA
 #endif
 
 #include <cmath>
+#include <filesystem>
 #include <fstream>
 #include <iostream>
 #include <memory>
@@ -769,8 +770,11 @@ namespace Step70
 
   // In the constructor, we create the mpi_communicator as well as
   // the triangulations and dof_handler for both the fluid and the solid.
-  // Using the mpi_communicator, both the ConditionalOStream and TimerOutput
+  // Using the `mpi_communicator`, both the ConditionalOStream and TimerOutput
   // object are constructed.
+  //
+  // In the constructor, we also check whether the output directory
+  // specified in the input file exists and, if not, create it.
   template <int dim, int spacedim>
   StokesImmersedProblem<dim, spacedim>::StokesImmersedProblem(
     const StokesImmersedProblemParameters<dim, spacedim> &par)
@@ -792,7 +796,17 @@ namespace Step70
                    Triangulation<dim, spacedim>::smoothing_on_coarsening))
     , fluid_dh(fluid_tria)
     , solid_dh(solid_tria)
-  {}
+  {
+    if (std::filesystem::exists(par.output_directory))
+      {
+        Assert(std::filesystem::is_directory(par.output_directory),
+               ExcMessage("You specified <" + par.output_directory +
+                          "> as the output directory in the input file, "
+                          "but this is not in fact a directory."));
+      }
+    else
+      std::filesystem::create_directory(par.output_directory);
+  }
 
 
   // In order to generate the grid, we first try to use the functions in the

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.