]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Write test hdf5_07
authorDaniel Garcia-Sanchez <daniel.garcia-sanchez@insp.upmc.fr>
Sat, 3 Apr 2021 19:15:01 +0000 (21:15 +0200)
committerDaniel Garcia-Sanchez <daniel.garcia-sanchez@insp.upmc.fr>
Sat, 3 Apr 2021 19:15:01 +0000 (21:15 +0200)
tests/base/hdf5_07.cc [new file with mode: 0644]
tests/base/hdf5_07.with_hdf5=true.mpirun=1.output [new file with mode: 0644]
tests/base/hdf5_07.with_hdf5=true.mpirun=4.output [new file with mode: 0644]

diff --git a/tests/base/hdf5_07.cc b/tests/base/hdf5_07.cc
new file mode 100644 (file)
index 0000000..fc97b56
--- /dev/null
@@ -0,0 +1,131 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2015 - 2019 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 at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+// Test bool with parallel HDF5
+// This test is based on tests/base/hdf5_02.cc
+
+#include <deal.II/base/hdf5.h>
+
+#include "../tests.h"
+
+// all include files you need here
+
+void
+test()
+{
+  std::string filename = "test.h5";
+
+  MPI_Comm mpi_communicator = MPI_COMM_WORLD;
+
+  // Write data
+  {
+    // Create file
+    HDF5::File data_file(filename,
+                         HDF5::File::FileAccessMode::create,
+                         mpi_communicator);
+
+    // Create attributes attached to the root
+    data_file.set_attribute("root_true", true);
+    data_file.set_attribute("root_false", false);
+
+    // Create attributes attached to a group
+    auto group = data_file.create_group("test_group");
+
+    group.set_attribute("group_true", true);
+    group.set_attribute("group_false", false);
+
+
+
+    std::string dataset_name("test_dataset");
+
+
+    const std::vector<hsize_t> dataset_dimensions = {2, 5, 3};
+    auto                       dataset =
+      group.template create_dataset<double>(dataset_name, dataset_dimensions);
+
+
+    dataset.set_attribute("dataset_true", true);
+    dataset.set_attribute("dataset_false", false);
+  }
+
+  // Read data
+  {
+    // Read attributes attached to the root
+    HDF5::File data_file(filename,
+                         HDF5::File::FileAccessMode::open,
+                         mpi_communicator);
+    auto       root_true  = data_file.get_attribute<bool>("root_true");
+    auto       root_false = data_file.get_attribute<bool>("root_false");
+    deallog << "root_true:" << root_true << std::endl;
+    deallog << "root_false:" << root_false << std::endl;
+
+    // Read attributes attached to a group
+    auto test_group = data_file.open_group("test_group");
+    deallog << "group_name: " << test_group.get_name() << std::endl;
+    auto group_true  = test_group.get_attribute<bool>("group_true");
+    auto group_false = test_group.get_attribute<bool>("group_false");
+    deallog << "group_true:" << group_true << std::endl;
+    deallog << "group_false:" << group_false << std::endl;
+
+    // Read attributes attached to a dataset
+    auto test_dataset = test_group.open_dataset("test_dataset");
+    deallog << "dataset_name: " << test_dataset.get_name() << std::endl;
+    auto dataset_true  = test_dataset.get_attribute<bool>("dataset_true");
+    auto dataset_false = test_dataset.get_attribute<bool>("dataset_false");
+    deallog << "dataset_true:" << dataset_true << std::endl;
+    deallog << "dataset_false:" << dataset_false << std::endl;
+  }
+}
+
+
+
+int
+main(int argc, char **argv)
+{
+  initlog();
+
+  try
+    {
+      Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
+
+      test();
+    }
+  catch (std::exception &exc)
+    {
+      std::cerr << std::endl
+                << std::endl
+                << "----------------------------------------------------"
+                << std::endl;
+      std::cerr << "Exception on processing: " << std::endl
+                << exc.what() << std::endl
+                << "Aborting!" << std::endl
+                << "----------------------------------------------------"
+                << std::endl;
+
+      return 1;
+    }
+  catch (...)
+    {
+      std::cerr << std::endl
+                << std::endl
+                << "----------------------------------------------------"
+                << std::endl;
+      std::cerr << "Unknown exception!" << std::endl
+                << "Aborting!" << std::endl
+                << "----------------------------------------------------"
+                << std::endl;
+      return 1;
+    };
+}
diff --git a/tests/base/hdf5_07.with_hdf5=true.mpirun=1.output b/tests/base/hdf5_07.with_hdf5=true.mpirun=1.output
new file mode 100644 (file)
index 0000000..272c63d
--- /dev/null
@@ -0,0 +1,9 @@
+
+DEAL::root_true:1
+DEAL::root_false:0
+DEAL::group_name: test_group
+DEAL::group_true:1
+DEAL::group_false:0
+DEAL::dataset_name: test_dataset
+DEAL::dataset_true:1
+DEAL::dataset_false:0
diff --git a/tests/base/hdf5_07.with_hdf5=true.mpirun=4.output b/tests/base/hdf5_07.with_hdf5=true.mpirun=4.output
new file mode 100644 (file)
index 0000000..272c63d
--- /dev/null
@@ -0,0 +1,9 @@
+
+DEAL::root_true:1
+DEAL::root_false:0
+DEAL::group_name: test_group
+DEAL::group_true:1
+DEAL::group_false:0
+DEAL::dataset_name: test_dataset
+DEAL::dataset_true:1
+DEAL::dataset_false:0

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.