]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Test for HDF5 now runs in parallel 10886/head
authorPasquale Africa <pasqualeclaudio.africa@polimi.it>
Thu, 3 Sep 2020 12:53:09 +0000 (12:53 +0000)
committerPasquale Africa <pasqualeclaudio.africa@polimi.it>
Mon, 21 Sep 2020 13:35:22 +0000 (13:35 +0000)
tests/simplex/data_out_write_hdf5_01.cc
tests/simplex/data_out_write_hdf5_01.mpirun=4.with_simplex_support=on.with_hdf5=on.output [deleted file]
tests/simplex/data_out_write_hdf5_01.with_simplex_support=on.with_hdf5=on.output [new file with mode: 0644]
tests/simplex/data_out_write_hdf5_02.cc [new file with mode: 0644]
tests/simplex/data_out_write_hdf5_02.mpirun=4.with_simplex_support=on.with_hdf5=on.output [new file with mode: 0644]

index 48f03976fbf07adbbbb9942ff97914e01bc8a3e9..6decd2d490864852edd34cd3742a77e4d7a212ae 100644 (file)
@@ -73,47 +73,44 @@ test(const FiniteElement<dim, spacedim> &fe, const unsigned int n_components)
 
   static unsigned int counter = 0;
 
-  for (unsigned int n_subdivisions = 1; n_subdivisions <= 2; ++n_subdivisions)
-    {
-      DataOut<dim> data_out;
+  DataOut<dim> data_out;
 
-      data_out.attach_dof_handler(dof_handler);
-      data_out.add_data_vector(solution, "solution");
+  data_out.attach_dof_handler(dof_handler);
+  data_out.add_data_vector(solution, "solution");
 
-      data_out.build_patches(mapping, n_subdivisions);
+  data_out.build_patches(mapping);
 
-      const std::string output_basename("test." + std::to_string(dim) + "." +
-                                        std::to_string(counter++));
+  const std::string output_basename("test." + std::to_string(dim) + "." +
+                                    std::to_string(counter++));
 
-      DataOutBase::DataOutFilter data_filter(
-        DataOutBase::DataOutFilterFlags(true, true));
-      data_out.write_filtered_data(data_filter);
-      data_out.write_hdf5_parallel(data_filter,
-                                   output_basename + ".h5",
-                                   MPI_COMM_SELF);
+  DataOutBase::DataOutFilter data_filter(
+    DataOutBase::DataOutFilterFlags(true, true));
+  data_out.write_filtered_data(data_filter);
+  data_out.write_hdf5_parallel(data_filter,
+                               output_basename + ".h5",
+                               MPI_COMM_SELF);
 
-      std::vector<XDMFEntry> xdmf_entries({data_out.create_xdmf_entry(
-        data_filter, output_basename + ".h5", 0, MPI_COMM_SELF)});
+  std::vector<XDMFEntry> xdmf_entries({data_out.create_xdmf_entry(
+    data_filter, output_basename + ".h5", 0, MPI_COMM_SELF)});
 
-      data_out.write_xdmf_file(xdmf_entries,
-                               output_basename + ".xdmf",
-                               MPI_COMM_SELF);
+  data_out.write_xdmf_file(xdmf_entries,
+                           output_basename + ".xdmf",
+                           MPI_COMM_SELF);
 
-      data_out.clear();
+  data_out.clear();
 
-      // Sadly hdf5 is binary and we can not use hd5dump because it might
-      // not be in the path. At least we can make sure that both the xdmf and
-      // the h5 file are created.
-      std::ifstream h5((output_basename + ".h5").c_str());
-      AssertThrow(h5.good(), ExcIO());
+  // Sadly hdf5 is binary and we can not use hd5dump because it might
+  // not be in the path. At least we can make sure that both the xdmf and
+  // the h5 file are created.
+  std::ifstream h5((output_basename + ".h5").c_str());
+  AssertThrow(h5.good(), ExcIO());
 
-      std::ifstream xdmf((output_basename + ".xdmf").c_str());
-      AssertThrow(h5.good(), ExcIO());
+  std::ifstream xdmf((output_basename + ".xdmf").c_str());
+  AssertThrow(h5.good(), ExcIO());
 
-      deallog << "Files " << output_basename + ".h5"
-              << " and " << output_basename + ".xdmf"
-              << " created succesfully!" << std::endl;
-    }
+  deallog << "Files " << output_basename + ".h5"
+          << " and " << output_basename + ".xdmf"
+          << " created succesfully!" << std::endl;
 }
 
 int
@@ -121,26 +118,20 @@ main(int argc, char **argv)
 {
   initlog();
 
-  Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
-
   {
     const unsigned int dim = 2;
-    test<dim>(Simplex::FE_P<dim>(2) /*=degree*/, 1);
-    test<dim>(FESystem<dim>(Simplex::FE_P<dim>(2 /*=degree*/), dim), dim);
-    test<dim>(FESystem<dim>(Simplex::FE_P<dim>(2 /*=degree*/),
-                            dim,
-                            Simplex::FE_P<dim>(1 /*=degree*/),
-                            1),
-              dim + 1);
+    test<dim>(Simplex::FE_P<dim>(2), 1);
+    test<dim>(FESystem<dim>(Simplex::FE_P<dim>(2), dim), dim);
+    test<dim>(
+      FESystem<dim>(Simplex::FE_P<dim>(2), dim, Simplex::FE_P<dim>(1), 1),
+      dim + 1);
   }
   {
     const unsigned int dim = 3;
-    test<dim>(Simplex::FE_P<dim>(2) /*=degree*/, 1);
-    test<dim>(FESystem<dim>(Simplex::FE_P<dim>(2 /*=degree*/), dim), dim);
-    test<dim>(FESystem<dim>(Simplex::FE_P<dim>(2 /*=degree*/),
-                            dim,
-                            Simplex::FE_P<dim>(1 /*=degree*/),
-                            1),
-              dim + 1);
+    test<dim>(Simplex::FE_P<dim>(2), 1);
+    test<dim>(FESystem<dim>(Simplex::FE_P<dim>(2), dim), dim);
+    test<dim>(
+      FESystem<dim>(Simplex::FE_P<dim>(2), dim, Simplex::FE_P<dim>(1), 1),
+      dim + 1);
   }
 }
diff --git a/tests/simplex/data_out_write_hdf5_01.mpirun=4.with_simplex_support=on.with_hdf5=on.output b/tests/simplex/data_out_write_hdf5_01.mpirun=4.with_simplex_support=on.with_hdf5=on.output
deleted file mode 100644 (file)
index 553a7f5..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-
-DEAL::Files test.2.0.h5 and test.2.0.xdmf created succesfully!
-DEAL::Files test.2.1.h5 and test.2.1.xdmf created succesfully!
-DEAL::Files test.2.2.h5 and test.2.2.xdmf created succesfully!
-DEAL::Files test.2.3.h5 and test.2.3.xdmf created succesfully!
-DEAL::Files test.2.4.h5 and test.2.4.xdmf created succesfully!
-DEAL::Files test.2.5.h5 and test.2.5.xdmf created succesfully!
-DEAL::Files test.3.0.h5 and test.3.0.xdmf created succesfully!
-DEAL::Files test.3.1.h5 and test.3.1.xdmf created succesfully!
-DEAL::Files test.3.2.h5 and test.3.2.xdmf created succesfully!
-DEAL::Files test.3.3.h5 and test.3.3.xdmf created succesfully!
-DEAL::Files test.3.4.h5 and test.3.4.xdmf created succesfully!
-DEAL::Files test.3.5.h5 and test.3.5.xdmf created succesfully!
\ No newline at end of file
diff --git a/tests/simplex/data_out_write_hdf5_01.with_simplex_support=on.with_hdf5=on.output b/tests/simplex/data_out_write_hdf5_01.with_simplex_support=on.with_hdf5=on.output
new file mode 100644 (file)
index 0000000..a967ed4
--- /dev/null
@@ -0,0 +1,7 @@
+
+DEAL::Files test.2.0.h5 and test.2.0.xdmf created succesfully!
+DEAL::Files test.2.1.h5 and test.2.1.xdmf created succesfully!
+DEAL::Files test.2.2.h5 and test.2.2.xdmf created succesfully!
+DEAL::Files test.3.0.h5 and test.3.0.xdmf created succesfully!
+DEAL::Files test.3.1.h5 and test.3.1.xdmf created succesfully!
+DEAL::Files test.3.2.h5 and test.3.2.xdmf created succesfully!
\ No newline at end of file
diff --git a/tests/simplex/data_out_write_hdf5_02.cc b/tests/simplex/data_out_write_hdf5_02.cc
new file mode 100644 (file)
index 0000000..9b17353
--- /dev/null
@@ -0,0 +1,164 @@
+// ---------------------------------------------------------------------
+//
+// 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 DataOut with HDF5 for simplex meshes in parallel.
+
+#include <deal.II/base/mpi.h>
+
+#include <deal.II/distributed/fully_distributed_tria.h>
+
+#include <deal.II/dofs/dof_handler.h>
+#include <deal.II/dofs/dof_tools.h>
+
+#include <deal.II/fe/fe_system.h>
+#include <deal.II/fe/mapping_fe.h>
+
+#include <deal.II/grid/grid_in.h>
+#include <deal.II/grid/grid_out.h>
+#include <deal.II/grid/tria.h>
+
+#include <deal.II/numerics/data_out.h>
+#include <deal.II/numerics/vector_tools.h>
+
+#include <deal.II/simplex/fe_lib.h>
+#include <deal.II/simplex/grid_generator.h>
+
+#include "../tests.h"
+
+using namespace dealii;
+
+template <int dim>
+class RightHandSideFunction : public Function<dim>
+{
+public:
+  RightHandSideFunction(const unsigned int n_components)
+    : Function<dim>(n_components)
+  {}
+
+  virtual double
+  value(const Point<dim> &p, const unsigned int component = 0) const
+  {
+    return p[component % dim] * p[component % dim];
+  }
+};
+
+template <int dim, int spacedim = dim>
+void
+test(const FiniteElement<dim, spacedim> &fe, const unsigned int n_components)
+{
+  MPI_Comm comm = MPI_COMM_WORLD;
+
+  parallel::fullydistributed::Triangulation<dim> tria(comm);
+
+  {
+    Triangulation<dim, spacedim> tria_serial;
+    GridGenerator::subdivided_hyper_cube_with_simplices(tria_serial,
+                                                        dim == 2 ? 4 : 2);
+
+    GridTools::partition_triangulation(Utilities::MPI::n_mpi_processes(comm),
+                                       tria_serial);
+
+    auto construction_data = TriangulationDescription::Utilities::
+      create_description_from_triangulation(tria_serial, comm);
+
+    tria.create_triangulation(construction_data);
+  }
+
+  DoFHandler<dim> dof_handler(tria);
+  dof_handler.distribute_dofs(fe);
+
+  IndexSet owned_dofs = dof_handler.locally_owned_dofs();
+  IndexSet locally_relevant_dofs;
+  DoFTools::extract_locally_relevant_dofs(dof_handler, locally_relevant_dofs);
+
+  LinearAlgebra::distributed::Vector<double> solution;
+
+  solution.reinit(owned_dofs, locally_relevant_dofs, comm);
+
+  MappingFE<dim> mapping(Simplex::FE_P<dim>(1));
+
+  VectorTools::interpolate(mapping,
+                           dof_handler,
+                           RightHandSideFunction<dim>(n_components),
+                           solution);
+  solution.update_ghost_values();
+
+  static unsigned int counter = 0;
+
+  DataOut<dim> data_out;
+
+  data_out.attach_dof_handler(dof_handler);
+  data_out.add_data_vector(solution, "solution");
+
+  data_out.build_patches(mapping);
+
+  const std::string output_basename("test." + std::to_string(dim) + "." +
+                                    std::to_string(counter++));
+
+  DataOutBase::DataOutFilter data_filter(
+    DataOutBase::DataOutFilterFlags(true, true));
+  data_out.write_filtered_data(data_filter);
+  data_out.write_hdf5_parallel(data_filter, output_basename + ".h5", comm);
+
+  std::vector<XDMFEntry> xdmf_entries({data_out.create_xdmf_entry(
+    data_filter, output_basename + ".h5", 0, comm)});
+
+  data_out.write_xdmf_file(xdmf_entries, output_basename + ".xdmf", comm);
+
+  data_out.clear();
+
+  // Sadly HDF5 is binary and we can not use hd5dump because it might not be
+  // in the path. At least we can make sure that both the .xdmf and the .h5
+  // files are created.
+  if (Utilities::MPI::this_mpi_process(comm) == 0)
+    {
+      std::ifstream h5((output_basename + ".h5").c_str());
+      AssertThrow(h5.good(), ExcIO());
+
+      std::ifstream xdmf((output_basename + ".xdmf").c_str());
+      AssertThrow(h5.good(), ExcIO());
+
+      deallog << "Files " << output_basename + ".h5"
+              << " and " << output_basename + ".xdmf"
+              << " created succesfully!" << std::endl;
+    }
+}
+
+int
+main(int argc, char **argv)
+{
+  initlog();
+
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
+
+  {
+    const unsigned int dim = 2;
+    test<dim>(Simplex::FE_P<dim>(2), 1);
+    test<dim>(FESystem<dim>(Simplex::FE_P<dim>(2), dim), dim);
+    test<dim>(
+      FESystem<dim>(Simplex::FE_P<dim>(2), dim, Simplex::FE_P<dim>(1), 1),
+      dim + 1);
+  }
+  {
+    const unsigned int dim = 3;
+    test<dim>(Simplex::FE_P<dim>(2), 1);
+    test<dim>(FESystem<dim>(Simplex::FE_P<dim>(2), dim), dim);
+    test<dim>(
+      FESystem<dim>(Simplex::FE_P<dim>(2), dim, Simplex::FE_P<dim>(1), 1),
+      dim + 1);
+  }
+}
diff --git a/tests/simplex/data_out_write_hdf5_02.mpirun=4.with_simplex_support=on.with_hdf5=on.output b/tests/simplex/data_out_write_hdf5_02.mpirun=4.with_simplex_support=on.with_hdf5=on.output
new file mode 100644 (file)
index 0000000..a967ed4
--- /dev/null
@@ -0,0 +1,7 @@
+
+DEAL::Files test.2.0.h5 and test.2.0.xdmf created succesfully!
+DEAL::Files test.2.1.h5 and test.2.1.xdmf created succesfully!
+DEAL::Files test.2.2.h5 and test.2.2.xdmf created succesfully!
+DEAL::Files test.3.0.h5 and test.3.0.xdmf created succesfully!
+DEAL::Files test.3.1.h5 and test.3.1.xdmf created succesfully!
+DEAL::Files test.3.2.h5 and test.3.2.xdmf created succesfully!
\ No newline at end of file

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.