]> https://gitweb.dealii.org/ - dealii.git/commitdiff
DataOut::write_vtu_with_pvtu_record(): prints the path name if file cannot be opened 10836/head
authorPeter Munch <peterrmuench@gmail.com>
Mon, 17 Aug 2020 21:38:11 +0000 (23:38 +0200)
committerPeter Munch <peterrmuench@gmail.com>
Mon, 17 Aug 2020 23:01:45 +0000 (01:01 +0200)
source/base/data_out_base.cc
tests/data_out/write_vtu_with_pvtu_record_no_folder_01.cc [new file with mode: 0644]
tests/data_out/write_vtu_with_pvtu_record_no_folder_01.mpirun=1.output [new file with mode: 0644]
tests/data_out/write_vtu_with_pvtu_record_no_folder_01.mpirun=2.output [new file with mode: 0644]

index 3d64d59ba6f81e4996029a8714229b590f6e389e..9ab011e5ae29dde1b3fd67ccffe1487b80108b61 100644 (file)
@@ -7024,6 +7024,7 @@ DataOutInterface<dim, spacedim>::write_vtu_in_parallel(
   (void)comm;
 
   std::ofstream f(filename);
+  AssertThrow(f, ExcFileNotOpen(filename));
   write_vtu(f);
 #else
 
@@ -7038,7 +7039,7 @@ DataOutInterface<dim, spacedim>::write_vtu_in_parallel(
                        MPI_MODE_CREATE | MPI_MODE_WRONLY,
                        info,
                        &fh);
-  AssertThrowMPI(ierr);
+  AssertThrow(ierr == MPI_SUCCESS, ExcFileNotOpen(filename));
 
   ierr = MPI_File_set_size(fh, 0); // delete the file contents
   AssertThrowMPI(ierr);
@@ -7160,6 +7161,7 @@ DataOutInterface<dim, spacedim>::write_vtu_with_pvtu_record(
     {
       // every processor writes one file
       std::ofstream output(filename.c_str());
+      AssertThrow(output, ExcFileNotOpen(filename));
       this->write_vtu(output);
     }
   else if (n_groups == 1)
diff --git a/tests/data_out/write_vtu_with_pvtu_record_no_folder_01.cc b/tests/data_out/write_vtu_with_pvtu_record_no_folder_01.cc
new file mode 100644 (file)
index 0000000..790f98f
--- /dev/null
@@ -0,0 +1,105 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2020 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+// Test that DataOut::write_vtu_with_pvtu_record() prints the path name
+// if a file cannot be opened.
+
+#include <deal.II/base/mpi.h>
+
+#include <deal.II/distributed/fully_distributed_tria.h>
+#include <deal.II/distributed/shared_tria.h>
+#include <deal.II/distributed/tria.h>
+
+#include <deal.II/fe/fe_dgq.h>
+
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/grid_out.h>
+#include <deal.II/grid/grid_tools.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/tria_description.h>
+
+#include <deal.II/numerics/data_out.h>
+
+#include <sstream>
+
+#include "../tests.h"
+
+using namespace dealii;
+
+
+int
+main(int argc, char *argv[])
+{
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
+  MPILogInitAll                    all;
+
+  const unsigned int dim = 2;
+
+  const MPI_Comm comm = MPI_COMM_WORLD;
+
+  parallel::distributed::Triangulation<dim> tria(comm);
+
+  GridGenerator::subdivided_hyper_cube(tria, 2);
+
+  FE_DGQ<dim>     fe(2);
+  DoFHandler<dim> dof_handler(tria);
+  dof_handler.distribute_dofs(fe);
+
+  Vector<double> vec(dof_handler.n_dofs());
+
+  DataOut<dim> data_out;
+
+  data_out.attach_dof_handler(dof_handler);
+  data_out.add_data_vector(vec, "solution");
+
+  const auto print_line = [](const std::string &str) {
+    std::stringstream ss(str);
+    std::string       token;
+
+    for (unsigned int i = 0; i < 8; ++i)
+      std::getline(ss, token, '\n');
+
+    deallog << token << std::endl;
+  };
+
+  try
+    {
+      data_out.write_vtu_with_pvtu_record("./folder/", "file", 0, comm, 1, 0);
+    }
+  catch (const std::exception &exc)
+    {
+      print_line(exc.what());
+    }
+
+  try
+    {
+      data_out.write_vtu_with_pvtu_record("./folder/", "file", 0, comm, 1, 1);
+    }
+  catch (const std::exception &exc)
+    {
+      print_line(exc.what());
+    }
+
+  try
+    {
+      data_out.write_vtu_with_pvtu_record(
+        "./folder/", "file", 0, comm, 1, Utilities::MPI::n_mpi_processes(comm));
+    }
+  catch (const std::exception &exc)
+    {
+      print_line(exc.what());
+    }
+}
diff --git a/tests/data_out/write_vtu_with_pvtu_record_no_folder_01.mpirun=1.output b/tests/data_out/write_vtu_with_pvtu_record_no_folder_01.mpirun=1.output
new file mode 100644 (file)
index 0000000..5b42282
--- /dev/null
@@ -0,0 +1,4 @@
+
+DEAL:0::    Could not open file ./folder/file_0.0.vtu.
+DEAL:0::    Could not open file ./folder/file_0.0.vtu.
+DEAL:0::    Could not open file ./folder/file_0.0.vtu.
diff --git a/tests/data_out/write_vtu_with_pvtu_record_no_folder_01.mpirun=2.output b/tests/data_out/write_vtu_with_pvtu_record_no_folder_01.mpirun=2.output
new file mode 100644 (file)
index 0000000..fd61454
--- /dev/null
@@ -0,0 +1,9 @@
+
+DEAL:0::    Could not open file ./folder/file_0.0.vtu.
+DEAL:0::    Could not open file ./folder/file_0.0.vtu.
+DEAL:0::    Could not open file ./folder/file_0.0.vtu.
+
+DEAL:1::    Could not open file ./folder/file_0.1.vtu.
+DEAL:1::    Could not open file ./folder/file_0.0.vtu.
+DEAL:1::    Could not open file ./folder/file_0.1.vtu.
+

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.