From: Giovanni Alzetta Date: Tue, 28 Nov 2017 16:49:33 +0000 (+0100) Subject: Adding serialize for CellId X-Git-Tag: v9.0.0-rc1~715^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3a62788e5877d7dd659a8f52bee5805b95fcb057;p=dealii.git Adding serialize for CellId --- diff --git a/doc/news/changes/minor/20171128GiovanniAlzetta b/doc/news/changes/minor/20171128GiovanniAlzetta new file mode 100644 index 0000000000..5b6ba218ba --- /dev/null +++ b/doc/news/changes/minor/20171128GiovanniAlzetta @@ -0,0 +1,3 @@ +New: Added CellId::serialize function and a test for it using pack/unpack +
+(Giovanni Alzetta, 2017/11/28) diff --git a/include/deal.II/grid/cell_id.h b/include/deal.II/grid/cell_id.h index 858117c191..95c1bc1297 100644 --- a/include/deal.II/grid/cell_id.h +++ b/include/deal.II/grid/cell_id.h @@ -141,6 +141,12 @@ public: */ bool operator<(const CellId &other) const; + /** + * Boost serialization function + */ + template + 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 +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 index 0000000000..619c8bbdb9 --- /dev/null +++ b/tests/grid/cell_id_05.cc @@ -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 +#include +#include +#include +#include +#include +#include +#include + +template +void test(const unsigned int &ref) +{ + + + Triangulation 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 >(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 index 0000000000..7ca52c43a9 --- /dev/null +++ b/tests/grid/cell_id_05.output @@ -0,0 +1,4 @@ + +DEAL::OK! +DEAL::OK! +DEAL::OK!