Skip to content

Commit

Permalink
Merge pull request dealii#5542 from GivAlz/new_serialize_cellid
Browse files Browse the repository at this point in the history
Adding serialize for CellId
  • Loading branch information
bangerth authored Nov 28, 2017
2 parents 5873e54 + 3a62788 commit 95febae
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/news/changes/minor/20171128GiovanniAlzetta
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
New: Added CellId::serialize function and a test for it using pack/unpack
<br>
(Giovanni Alzetta, 2017/11/28)
17 changes: 17 additions & 0 deletions include/deal.II/grid/cell_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ class CellId
*/
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
Expand Down Expand Up @@ -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.
*/
Expand Down
70 changes: 70 additions & 0 deletions tests/grid/cell_id_05.cc
Original file line number Diff line number Diff line change
@@ -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);
}
4 changes: 4 additions & 0 deletions tests/grid/cell_id_05.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

DEAL::OK!
DEAL::OK!
DEAL::OK!

0 comments on commit 95febae

Please sign in to comment.