From: Giovanni Alzetta Date: Fri, 24 Nov 2017 11:27:14 +0000 (+0100) Subject: Adding serialize function to boundingbox class and test X-Git-Tag: v9.0.0-rc1~730^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F5526%2Fhead;p=dealii.git Adding serialize function to boundingbox class and test --- diff --git a/doc/news/changes/minor/20171124GiovanniAlzetta b/doc/news/changes/minor/20171124GiovanniAlzetta new file mode 100644 index 0000000000..d81c0ce932 --- /dev/null +++ b/doc/news/changes/minor/20171124GiovanniAlzetta @@ -0,0 +1,3 @@ +New: Added BoundingBox::serialize function and a test for it using pack/unpack functions +
+(Giovanni Alzetta, 2017/11/24) diff --git a/include/deal.II/base/bounding_box.h b/include/deal.II/base/bounding_box.h index 302e9c5fa5..13271a7090 100644 --- a/include/deal.II/base/bounding_box.h +++ b/include/deal.II/base/bounding_box.h @@ -20,6 +20,7 @@ #include #include #include +#include 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 class BoundingBox @@ -134,8 +136,14 @@ public: */ double volume() const; + /** + * Boost serialization function + */ + template + void serialize(Archive &ar, const unsigned int version ); + private: - std::pair,Point> boundary_points; + std::pair,Point> boundary_points; }; /*------------------------------- Inline functions: BoundingBox ---------------------------*/ @@ -155,6 +163,14 @@ BoundingBox::BoundingBox (const std::pairboundary_points = boundary_points; } + +template +template +void BoundingBox::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 index 0000000000..5f043c669e --- /dev/null +++ b/tests/base/bounding_box_4.cc @@ -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 +#include +#include + +template +void test(const unsigned int &size) +{ + std::vector< BoundingBox > b_boxes(size); + + for (auto &b : b_boxes) + { + auto p1 = random_point(); + auto p2 = p1; + for (unsigned int i=0; i( std::make_pair(p1,p2) ); + } + + auto buffer = Utilities::pack(b_boxes); + + auto unpacked = Utilities::unpack > >(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 index 0000000000..7ca52c43a9 --- /dev/null +++ b/tests/base/bounding_box_4.output @@ -0,0 +1,4 @@ + +DEAL::OK! +DEAL::OK! +DEAL::OK!