From: Martin Kronbichler Date: Wed, 22 Feb 2017 11:59:53 +0000 (+0100) Subject: Make sure to clear all variables in MGTransferMatrixFree. X-Git-Tag: v8.5.0-rc1~103^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2c226cc62eb5e04e4e301000f0dc9b20604a698;p=dealii.git Make sure to clear all variables in MGTransferMatrixFree. --- diff --git a/doc/news/changes/minor/20170222MartinKronbichler b/doc/news/changes/minor/20170222MartinKronbichler new file mode 100644 index 0000000000..6118425882 --- /dev/null +++ b/doc/news/changes/minor/20170222MartinKronbichler @@ -0,0 +1,5 @@ +Fixed: The class MGTransferMatrixFree::clear() did not reset all member +variables, sometimes treating Dirichlet boundary conditions incorrectly if a +transfer object was reused. This is now fixed. +
+(Martin Kronbichler, 2017/02/22) diff --git a/source/multigrid/mg_transfer_matrix_free.cc b/source/multigrid/mg_transfer_matrix_free.cc index b2a7e72005..17e7b9f434 100644 --- a/source/multigrid/mg_transfer_matrix_free.cc +++ b/source/multigrid/mg_transfer_matrix_free.cc @@ -83,6 +83,7 @@ void MGTransferMatrixFree::clear () n_child_cell_dofs = 0; level_dof_indices.clear(); parent_child_connect.clear(); + dirichlet_indices.clear(); n_owned_level_cells.clear(); prolongation_matrix_1d.clear(); evaluation_data.clear(); @@ -101,7 +102,7 @@ void MGTransferMatrixFree::build internal::MGTransfer::ElementInfo elem_info; internal::MGTransfer::setup_transfer(mg_dof, - (const MGConstrainedDoFs *)this->mg_constrained_dofs, + this->mg_constrained_dofs, elem_info, level_dof_indices, parent_child_connect, diff --git a/tests/multigrid/transfer_matrix_free_09.cc b/tests/multigrid/transfer_matrix_free_09.cc new file mode 100644 index 0000000000..d5816e5632 --- /dev/null +++ b/tests/multigrid/transfer_matrix_free_09.cc @@ -0,0 +1,114 @@ +// --------------------------------------------------------------------- +// +// 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::clear works correctly by comparing a +// cleared 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; + 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.clear(); + transfer.initialize_constraints(mg_constrained_dofs); + 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); + mpi_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_09.output b/tests/multigrid/transfer_matrix_free_09.output new file mode 100644 index 0000000000..37eaf906a4 --- /dev/null +++ b/tests/multigrid/transfer_matrix_free_09.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