From 809a0b7cb84bc43941ff63db8beb995a79efc665 Mon Sep 17 00:00:00 2001 From: Pasquale Africa Date: Tue, 4 Jul 2023 19:53:07 +0000 Subject: [PATCH] Add test for shared triangulations --- tests/sharedtria/serialization_01.cc | 130 ++++++++++++++++++ .../serialization_01.mpirun=2.output | 47 +++++++ 2 files changed, 177 insertions(+) create mode 100644 tests/sharedtria/serialization_01.cc create mode 100644 tests/sharedtria/serialization_01.mpirun=2.output diff --git a/tests/sharedtria/serialization_01.cc b/tests/sharedtria/serialization_01.cc new file mode 100644 index 0000000000..3d612ef0a8 --- /dev/null +++ b/tests/sharedtria/serialization_01.cc @@ -0,0 +1,130 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2008 - 2018 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.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + +// Test serialization with shared triangulations. + +#include + +#include + +#include + +#include + +#include + +#include + +#include +#include + +#include "../grid/tests.h" + +using namespace dealii; + +template +class InterpolationFunction : public Function +{ +public: + InterpolationFunction() + : Function(1) + {} + + virtual double + value(const Point &p, const unsigned int component = 0) const + { + return p.norm(); + } +}; + +template +void +test(TriangulationType &triangulation) +{ + DoFHandler dof_handler(triangulation); + dof_handler.distribute_dofs(FE_Q(2)); + + using VectorType = Vector; + + VectorType vector(dof_handler.n_dofs()); + + VectorTools::interpolate(dof_handler, InterpolationFunction(), vector); + + VectorType vector_loaded(dof_handler.n_dofs()); + + print_statistics(triangulation, false); + + std::stringstream stream; + { + boost::archive::text_oarchive oa(stream); + oa << triangulation; + oa << vector; + } + + triangulation.clear(); + + { + boost::archive::text_iarchive ia(stream); + ia >> triangulation; + ia >> vector_loaded; + } + print_statistics(triangulation, false); + + // Verify that error is 0. + VectorType error(vector); + error.add(-1, vector_loaded); + + deallog << (error.linfty_norm() < 1e-16 ? "PASSED" : "FAILED") << std::endl; +} + +int +main(int argc, char *argv[]) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + MPILogInitAll all; + + deallog.push("2d"); + { + constexpr int dim = 2; + + parallel::shared::Triangulation triangulation( + MPI_COMM_WORLD, + ::Triangulation::none, + false, + parallel::shared::Triangulation::partition_metis); + GridGenerator::hyper_cube(triangulation); + triangulation.refine_global(3); + + test(triangulation); + } + deallog.pop(); + + deallog.push("3d"); + { + constexpr int dim = 3; + + parallel::shared::Triangulation triangulation( + MPI_COMM_WORLD, + ::Triangulation::none, + false, + parallel::shared::Triangulation::partition_metis); + GridGenerator::hyper_cube(triangulation); + triangulation.refine_global(3); + + test(triangulation); + } + deallog.pop(); +} diff --git a/tests/sharedtria/serialization_01.mpirun=2.output b/tests/sharedtria/serialization_01.mpirun=2.output new file mode 100644 index 0000000000..985cf7deff --- /dev/null +++ b/tests/sharedtria/serialization_01.mpirun=2.output @@ -0,0 +1,47 @@ + +DEAL:0:2d::n_levels: 4 +DEAL:0:2d::n_cells: 85 +DEAL:0:2d::n_active_cells: 64 +DEAL:0:2d::has_hanging_nodes: false +DEAL:0:2d:: +DEAL:0:2d::n_levels: 4 +DEAL:0:2d::n_cells: 85 +DEAL:0:2d::n_active_cells: 64 +DEAL:0:2d::has_hanging_nodes: false +DEAL:0:2d:: +DEAL:0:2d::PASSED +DEAL:0:3d::n_levels: 4 +DEAL:0:3d::n_cells: 585 +DEAL:0:3d::n_active_cells: 512 +DEAL:0:3d::has_hanging_nodes: false +DEAL:0:3d:: +DEAL:0:3d::n_levels: 4 +DEAL:0:3d::n_cells: 585 +DEAL:0:3d::n_active_cells: 512 +DEAL:0:3d::has_hanging_nodes: false +DEAL:0:3d:: +DEAL:0:3d::PASSED + +DEAL:1:2d::n_levels: 4 +DEAL:1:2d::n_cells: 85 +DEAL:1:2d::n_active_cells: 64 +DEAL:1:2d::has_hanging_nodes: false +DEAL:1:2d:: +DEAL:1:2d::n_levels: 4 +DEAL:1:2d::n_cells: 85 +DEAL:1:2d::n_active_cells: 64 +DEAL:1:2d::has_hanging_nodes: false +DEAL:1:2d:: +DEAL:1:2d::PASSED +DEAL:1:3d::n_levels: 4 +DEAL:1:3d::n_cells: 585 +DEAL:1:3d::n_active_cells: 512 +DEAL:1:3d::has_hanging_nodes: false +DEAL:1:3d:: +DEAL:1:3d::n_levels: 4 +DEAL:1:3d::n_cells: 585 +DEAL:1:3d::n_active_cells: 512 +DEAL:1:3d::has_hanging_nodes: false +DEAL:1:3d:: +DEAL:1:3d::PASSED + -- 2.39.5