From 8e7b94d80304152bd2f39f8e478493d268fbd3f2 Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Fri, 24 Mar 2017 09:55:25 +0100 Subject: [PATCH] Make sure to clean all data before filling MG transfer data fields --- source/multigrid/mg_transfer_internal.cc | 5 + tests/multigrid/transfer_matrix_free_10.cc | 112 ++++++++++ .../multigrid/transfer_matrix_free_10.output | 205 ++++++++++++++++++ 3 files changed, 322 insertions(+) create mode 100644 tests/multigrid/transfer_matrix_free_10.cc create mode 100644 tests/multigrid/transfer_matrix_free_10.output diff --git a/source/multigrid/mg_transfer_internal.cc b/source/multigrid/mg_transfer_internal.cc index 9b1873c366..31f24228b5 100644 --- a/source/multigrid/mg_transfer_internal.cc +++ b/source/multigrid/mg_transfer_internal.cc @@ -456,6 +456,11 @@ namespace internal std::vector > > ©_indices_global_mine, MGLevelObject > &ghosted_level_vector) { + level_dof_indices.clear(); + parent_child_connect.clear(); + n_owned_level_cells.clear(); + dirichlet_indices.clear(); + weights_on_refined.clear(); // we collect all child DoFs of a mother cell together. For faster // tensorized operations, we align the degrees of freedom diff --git a/tests/multigrid/transfer_matrix_free_10.cc b/tests/multigrid/transfer_matrix_free_10.cc new file mode 100644 index 0000000000..97b61c91af --- /dev/null +++ b/tests/multigrid/transfer_matrix_free_10.cc @@ -0,0 +1,112 @@ +// --------------------------------------------------------------------- +// +// 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. +// +// --------------------------------------------------------------------- + + +// Check that MGTransferMatrixFree::build works correctly by comparing the +// build on an already existing transfer system with a freshly constructed one +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +template +void check(const FiniteElement &fe) +{ + deallog.threshold_double(std::max(1e2*(double)std::numeric_limits::epsilon(), + 1e-11)); + deallog << "FE: " << fe.get_name() << std::endl; + + MGConstrainedDoFs mg_constrained_dofs; + MGTransferMatrixFree transfer(mg_constrained_dofs); + Triangulation tr(Triangulation::limit_level_difference_at_vertices); + GridGenerator::hyper_cube(tr); + tr.refine_global(6-dim); + + // run a few different sizes... + for (unsigned int c=0; c<4; ++c) + { + for (typename Triangulation::active_cell_iterator cell=tr.begin_active(); + cell != tr.end(); ++cell) + if ((cell->center().norm() < 0.5 && (cell->level() < 5 || + cell->center().norm() > 0.45) + || + (dim == 2 && cell->center().norm() > 1.2))) + cell->set_refine_flag(); + tr.execute_coarsening_and_refinement (); + + DoFHandler mgdof(tr); + mgdof.distribute_dofs(fe); + mgdof.distribute_mg_dofs(fe); + + Tensor<1,dim> exponents_monomial; + for (unsigned int d=0; d vref; + vref.reinit(mgdof.n_dofs()); + VectorTools::interpolate(mgdof, Functions::Monomial(exponents_monomial), vref); + + deallog << "no. cells: " << tr.n_global_active_cells() << std::endl; + + std::set dirichlet_boundary; + dirichlet_boundary.insert(0); + mg_constrained_dofs.initialize(mgdof); + mg_constrained_dofs.make_zero_boundary_constraints(mgdof, dirichlet_boundary); + + // build matrix-free transfer + transfer.build(mgdof); + MGTransferMatrixFree transfer_ref(mg_constrained_dofs); + transfer_ref.build(mgdof); + MGLevelObject > vectors(0, tr.n_global_levels()-1); + transfer_ref.copy_to_mg(mgdof, vectors, vref); + for (unsigned int level=vectors.max_level(); level>0; --level) + { + LinearAlgebra::distributed::Vector vec2(vectors[level-1]); + transfer_ref.restrict_and_add(level, vectors[level-1], vectors[level]); + transfer.restrict_and_add(level, vec2, vectors[level]); + vec2 -= vectors[level-1]; + deallog << "Error in restriction: " << (double)vec2.linfty_norm() << std::endl; + } + + for (unsigned int level=1; level vec2(vectors[level+1]); + transfer_ref.prolongate(level+1, vectors[level+1], vectors[level]); + transfer.prolongate(level+1, vec2, vectors[level]); + vec2 -= vectors[level+1]; + deallog << "Error in prolongation: " << (double)vec2.linfty_norm() << std::endl; + } + } +} + + +int main(int argc, char **argv) +{ + // no threading in this test... + Utilities::MPI::MPI_InitFinalize mpi(argc, argv, 1); + initlog(); + + check<2,double>(FE_DGQ<2>(2)); + check<2,double>(FE_Q<2>(2)); + check<3,double>(FE_Q<3>(1)); + check<2,float>(FE_Q<2>(2)); +} diff --git a/tests/multigrid/transfer_matrix_free_10.output b/tests/multigrid/transfer_matrix_free_10.output new file mode 100644 index 0000000000..37eaf906a4 --- /dev/null +++ b/tests/multigrid/transfer_matrix_free_10.output @@ -0,0 +1,205 @@ + +DEAL::FE: FE_DGQ<2>(2) +DEAL::no. cells: 448 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::no. cells: 766 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::no. cells: 1924 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::no. cells: 6082 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::FE: FE_Q<2>(2) +DEAL::no. cells: 448 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::no. cells: 766 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::no. cells: 1924 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::no. cells: 6082 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::FE: FE_Q<3>(1) +DEAL::no. cells: 757 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::no. cells: 2808 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::no. cells: 6847 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::no. cells: 33776 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::FE: FE_Q<2>(2) +DEAL::no. cells: 448 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::no. cells: 766 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::no. cells: 1924 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::no. cells: 6082 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in restriction: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 +DEAL::Error in prolongation: 0 -- 2.39.5