]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Adding serialize function to boundingbox class and test 5526/head
authorGiovanni Alzetta <giovannialzetta@hotmail.it>
Fri, 24 Nov 2017 11:27:14 +0000 (12:27 +0100)
committerGiovanni Alzetta <giovannialzetta@hotmail.it>
Fri, 24 Nov 2017 19:25:36 +0000 (20:25 +0100)
doc/news/changes/minor/20171124GiovanniAlzetta [new file with mode: 0644]
include/deal.II/base/bounding_box.h
tests/base/bounding_box_4.cc [new file with mode: 0644]
tests/base/bounding_box_4.output [new file with mode: 0644]

diff --git a/doc/news/changes/minor/20171124GiovanniAlzetta b/doc/news/changes/minor/20171124GiovanniAlzetta
new file mode 100644 (file)
index 0000000..d81c0ce
--- /dev/null
@@ -0,0 +1,3 @@
+New: Added BoundingBox::serialize function and a test for it using pack/unpack functions
+<br>
+(Giovanni Alzetta, 2017/11/24)
index 302e9c5fa578b5a13f7501ef108cc024fb35774b..13271a7090fdb0d1e91f997ab925189e9354897f 100644 (file)
@@ -20,6 +20,7 @@
 #include <deal.II/base/config.h>
 #include <deal.II/base/exceptions.h>
 #include <deal.II/base/point.h>
+#include <deal.II/base/utilities.h>
 
 DEAL_II_NAMESPACE_OPEN
 
@@ -86,6 +87,7 @@ enum class NeighborType
  * @endcode
  * Notice the sides are always parallel to the respective axis.
  *
+ * @author Giovanni Alzetta, 2017.
  */
 template <int spacedim, typename Number=double>
 class BoundingBox
@@ -134,8 +136,14 @@ public:
    */
   double volume() const;
 
+  /**
+   * Boost serialization function
+   */
+  template<class Archive>
+  void serialize(Archive &ar, const unsigned int version );
+
 private:
-  std::pair<Point<spacedim, Number>,Point<spacedim,Number>> boundary_points;
+  std::pair<Point<spacedim,Number>,Point<spacedim,Number>> boundary_points;
 };
 
 /*------------------------------- Inline functions: BoundingBox ---------------------------*/
@@ -155,6 +163,14 @@ BoundingBox<spacedim, Number>::BoundingBox (const std::pair<Point<spacedim,Numbe
   this->boundary_points = boundary_points;
 }
 
+
+template <int spacedim, typename Number>
+template<class Archive>
+void BoundingBox<spacedim, Number>::serialize(Archive &ar, const unsigned int /*version*/)
+{
+  ar &boundary_points;
+}
+
 #endif // DOXYGEN
 DEAL_II_NAMESPACE_CLOSE
 
diff --git a/tests/base/bounding_box_4.cc b/tests/base/bounding_box_4.cc
new file mode 100644 (file)
index 0000000..5f043c6
--- /dev/null
@@ -0,0 +1,74 @@
+// ---------------------------------------------------------------------
+//
+// 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 BoundingBox
+
+#include "../tests.h"
+
+#include <deal.II/base/utilities.h>
+#include <deal.II/base/point.h>
+#include <deal.II/base/bounding_box.h>
+
+template <int spacedim>
+void test(const unsigned int &size)
+{
+  std::vector< BoundingBox<spacedim> > b_boxes(size);
+
+  for (auto &b : b_boxes)
+    {
+      auto p1 = random_point<spacedim>();
+      auto p2 = p1;
+      for (unsigned int i=0; i<spacedim; ++i)
+        p2[i] += i;
+      b = BoundingBox<spacedim>( std::make_pair(p1,p2) );
+    }
+
+  auto buffer = Utilities::pack(b_boxes);
+
+  auto unpacked = Utilities::unpack<std::vector< BoundingBox<spacedim> > >(buffer);
+
+  unsigned int i=0;
+  bool ok = true;
+  for (auto &b : b_boxes)
+    {
+      const auto &b_points = b.get_boundary_points();
+      const auto &u_points = unpacked[i++].get_boundary_points();
+      if (b_points.first.distance(u_points.first) > 1e-12)
+        {
+          deallog << "NOT OK: "
+                  << b_points.first << " != " << u_points.first << std::endl;
+          ok = false;
+        }
+      else if ( b_points.second.distance(u_points.second) > 1e-12 )
+        {
+          deallog << "NOT OK: "
+                  << b_points.second << " != " << u_points.second << std::endl;
+          ok = false;
+        }
+    }
+
+  if (ok)
+    deallog << "OK!" << std::endl;
+}
+
+int main()
+{
+  initlog();
+
+  test<1>(10);
+  test<2>(20);
+  test<3>(30);
+}
diff --git a/tests/base/bounding_box_4.output b/tests/base/bounding_box_4.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.