]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix serialization of XDMFEntry class 7691/head
authorRene Gassmoeller <rene.gassmoeller@mailbox.org>
Mon, 4 Feb 2019 21:12:12 +0000 (13:12 -0800)
committerRene Gassmoeller <rene.gassmoeller@mailbox.org>
Mon, 4 Feb 2019 21:15:29 +0000 (13:15 -0800)
include/deal.II/base/data_out_base.h
tests/serialization/xdmf_entry.cc [new file with mode: 0644]
tests/serialization/xdmf_entry.output [new file with mode: 0644]

index 8e05a6aacbddd7df8f18208f8bcee958246ea4d4..2a6da9fd79e1b169fd1719ac08b7f71ca55b6e07 100644 (file)
@@ -26,6 +26,9 @@
 
 #include <deal.II/numerics/data_component_interpretation.h>
 
+// To be able to serialize XDMFEntry
+#include <boost/serialization/map.hpp>
+
 #include <limits>
 #include <string>
 #include <tuple>
@@ -3599,7 +3602,7 @@ public:
   serialize(Archive &ar, const unsigned int /*version*/)
   {
     ar &valid &h5_sol_filename &h5_mesh_filename &entry_time &num_nodes
-      &num_cells &dimension &attribute_dims;
+      &num_cells &dimension &space_dimension &attribute_dims;
   }
 
   /**
diff --git a/tests/serialization/xdmf_entry.cc b/tests/serialization/xdmf_entry.cc
new file mode 100644 (file)
index 0000000..2a3c3b5
--- /dev/null
@@ -0,0 +1,74 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 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.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+// check serialization for XDMFEntry
+
+#include <deal.II/base/data_out_base.h>
+
+#include "serialization.h"
+
+void
+test()
+{
+  const std::string mesh_filename     = "mesh.h5";
+  const std::string solution_filename = "solution.h5";
+
+  const double       time     = 0.5;
+  const unsigned int nodes    = 128;
+  const unsigned int cells    = 16;
+  const unsigned int dim      = 2;
+  const unsigned int spacedim = 3;
+
+  XDMFEntry entry1(
+    mesh_filename, solution_filename, time, nodes, cells, dim, spacedim);
+  XDMFEntry entry2;
+
+  // save data to archive
+  std::ostringstream oss;
+  {
+    boost::archive::text_oarchive oa(oss, boost::archive::no_header);
+    oa << entry1;
+    // archive and stream closed when destructors are called
+  }
+  deallog << oss.str() << std::endl;
+
+  // verify correctness of the serialization
+  {
+    std::istringstream            iss(oss.str());
+    boost::archive::text_iarchive ia(iss, boost::archive::no_header);
+    ia >> entry2;
+  }
+
+  deallog << "XDMFEntry before serialization: " << std::endl
+          << std::endl
+          << entry1.get_xdmf_content(0) << std::endl;
+
+  deallog << "XDMFEntry after de-serialization: " << std::endl
+          << std::endl
+          << entry2.get_xdmf_content(0) << std::endl;
+}
+
+
+int
+main()
+{
+  initlog();
+  deallog << std::setprecision(3);
+
+  test();
+
+  deallog << "OK" << std::endl;
+}
diff --git a/tests/serialization/xdmf_entry.output b/tests/serialization/xdmf_entry.output
new file mode 100644 (file)
index 0000000..fdeaefe
--- /dev/null
@@ -0,0 +1,36 @@
+
+DEAL::0 0 1 11 solution.h5 7 mesh.h5 5.00000000000000000e-01 128 16 2 3 0 0 0 0
+
+DEAL::XDMFEntry before serialization: 
+DEAL::
+DEAL::<Grid Name="mesh" GridType="Uniform">
+  <Time Value="0.5"/>
+  <Geometry GeometryType="XYZ">
+    <DataItem Dimensions="128 3" NumberType="Float" Precision="8" Format="HDF">
+      mesh.h5:/nodes
+    </DataItem>
+  </Geometry>
+  <Topology TopologyType="Quadrilateral" NumberOfElements="16">
+    <DataItem Dimensions="16 4" NumberType="UInt" Format="HDF">
+      mesh.h5:/cells
+    </DataItem>
+  </Topology>
+</Grid>
+
+DEAL::XDMFEntry after de-serialization: 
+DEAL::
+DEAL::<Grid Name="mesh" GridType="Uniform">
+  <Time Value="0.5"/>
+  <Geometry GeometryType="XYZ">
+    <DataItem Dimensions="128 3" NumberType="Float" Precision="8" Format="HDF">
+      mesh.h5:/nodes
+    </DataItem>
+  </Geometry>
+  <Topology TopologyType="Quadrilateral" NumberOfElements="16">
+    <DataItem Dimensions="16 4" NumberType="UInt" Format="HDF">
+      mesh.h5:/cells
+    </DataItem>
+  </Topology>
+</Grid>
+
+DEAL::OK

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.