]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Adding serialize for CellId 5542/head
authorGiovanni Alzetta <giovannialzetta@hotmail.it>
Tue, 28 Nov 2017 16:49:33 +0000 (17:49 +0100)
committerGiovanni Alzetta <giovannialzetta@hotmail.it>
Tue, 28 Nov 2017 16:49:33 +0000 (17:49 +0100)
doc/news/changes/minor/20171128GiovanniAlzetta [new file with mode: 0644]
include/deal.II/grid/cell_id.h
tests/grid/cell_id_05.cc [new file with mode: 0644]
tests/grid/cell_id_05.output [new file with mode: 0644]

diff --git a/doc/news/changes/minor/20171128GiovanniAlzetta b/doc/news/changes/minor/20171128GiovanniAlzetta
new file mode 100644 (file)
index 0000000..5b6ba21
--- /dev/null
@@ -0,0 +1,3 @@
+New: Added CellId::serialize function and a test for it using pack/unpack
+<br>
+(Giovanni Alzetta, 2017/11/28)
index 858117c191b10d6649ecf5bda610ac872171e3ed..95c1bc1297610581a27d38410dbfa25bf51a4a5e 100644 (file)
@@ -141,6 +141,12 @@ public:
    */
   bool operator<(const CellId &other) const;
 
+  /**
+   * Boost serialization function
+   */
+  template<class Archive>
+  void serialize(Archive &ar, const unsigned int version );
+
 private:
   /**
    * The number of the coarse cell within whose tree the cell
@@ -195,6 +201,17 @@ std::ostream &operator<< (std::ostream &os,
 
 
 
+/**
+ * Serialization function
+ */
+template<class Archive>
+void CellId::serialize(Archive &ar, const unsigned int /*version*/)
+{
+  ar &coarse_cell_id;
+  ar &n_child_indices;
+  ar &child_indices;
+}
+
 /**
  * Read a CellId object from a stream.
  */
diff --git a/tests/grid/cell_id_05.cc b/tests/grid/cell_id_05.cc
new file mode 100644 (file)
index 0000000..619c8bb
--- /dev/null
@@ -0,0 +1,70 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2017 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.
+//
+// ---------------------------------------------------------------------
+
+
+// testing serialize function for class CellId
+
+#include "../tests.h"
+
+#include <deal.II/base/utilities.h>
+#include <deal.II/base/point.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/tria_accessor.h>
+#include <deal.II/grid/tria_iterator.h>
+#include <deal.II/grid/tria_boundary.h>
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/cell_id.h>
+
+template <int spacedim>
+void test(const unsigned int &ref)
+{
+
+
+  Triangulation<spacedim> tria;
+  GridGenerator::hyper_cube (tria);
+  tria.refine_global(ref);
+  std::vector< CellId > cell_ids;
+  for (auto cell: tria.active_cell_iterators())
+    {
+      cell_ids.push_back(cell->id());
+    }
+
+  auto buffer = Utilities::pack(cell_ids);
+
+  auto unpacked = Utilities::unpack<std::vector< CellId > >(buffer);
+
+  unsigned int i=0;
+  bool ok = true;
+  for (auto cell: tria.active_cell_iterators())
+    {
+      if (cell->id() != unpacked[i++])
+        {
+          deallog << "NOT OK; problem with cell " << i << std::endl;
+          ok = false;
+        }
+    }
+
+  if (ok)
+    deallog << "OK!" << std::endl;
+}
+
+int main()
+{
+  initlog();
+
+  test<1>(4);
+  test<2>(3);
+  test<3>(2);
+}
diff --git a/tests/grid/cell_id_05.output b/tests/grid/cell_id_05.output
new file mode 100644 (file)
index 0000000..7ca52c4
--- /dev/null
@@ -0,0 +1,4 @@
+
+DEAL::OK!
+DEAL::OK!
+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.