From 528fe6aad73cb92fa216cf39f08b03e1517053ac Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Tue, 30 Jan 2018 11:19:01 +0100 Subject: [PATCH] Add test. --- tests/multigrid/transfer_matrix_free_08.cc | 3 +- tests/multigrid/transfer_matrix_free_12.cc | 116 ++++++++++++++++++ .../multigrid/transfer_matrix_free_12.output | 41 +++++++ 3 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 tests/multigrid/transfer_matrix_free_12.cc create mode 100644 tests/multigrid/transfer_matrix_free_12.output diff --git a/tests/multigrid/transfer_matrix_free_08.cc b/tests/multigrid/transfer_matrix_free_08.cc index 472a0e6e8f..bf079cf684 100644 --- a/tests/multigrid/transfer_matrix_free_08.cc +++ b/tests/multigrid/transfer_matrix_free_08.cc @@ -81,8 +81,9 @@ void check(const FiniteElement &fe) for (unsigned int level=1; level::epsilon(); deallog << "Error after prolongation: " - << (double)vec.back().linfty_norm() << std::endl; + << filter_out_small_numbers(vec.back().linfty_norm(), tolerance) << std::endl; // unfortunately, no completely trivial expression of what should happen // during restriction diff --git a/tests/multigrid/transfer_matrix_free_12.cc b/tests/multigrid/transfer_matrix_free_12.cc new file mode 100644 index 0000000000..dd6f9fa90d --- /dev/null +++ b/tests/multigrid/transfer_matrix_free_12.cc @@ -0,0 +1,116 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 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 at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + +// Similar to transfer_matrix_free_08 but using a system of equations: high +// polynomial degrees beyond 10 that are compared against a linear function +// that gets prolongated between the mesh levels. Since the function is +// linear, it should be exactly represented on the finest level. Then also +// look into the result of restriction + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +template +void check(const FiniteElement &fe_scalar) +{ + FESystem fe(fe_scalar, dim); + deallog << "FE: " << fe.get_name() << std::endl; + + // run a few different sizes... + + Triangulation tr(Triangulation::limit_level_difference_at_vertices); + GridGenerator::hyper_cube(tr); + tr.refine_global(2); + + Triangulation trcoarse(Triangulation::limit_level_difference_at_vertices); + GridGenerator::hyper_cube(trcoarse); + DoFHandler dofcoarse(trcoarse); + dofcoarse.distribute_dofs(fe); + Tensor<1,dim> exponents_monomial; + for (unsigned int d=0; d vrefcoarse; + vrefcoarse.reinit(dofcoarse.n_dofs()); + VectorTools::interpolate(dofcoarse, Functions::Monomial(exponents_monomial, dim), vrefcoarse); + + deallog << "no. cells: " << tr.n_global_active_cells() << std::endl; + + DoFHandler mgdof(tr); + mgdof.distribute_dofs(fe); + mgdof.distribute_mg_dofs(fe); + + // build matrix-free transfer + MGTransferMatrixFree transfer; + transfer.build(mgdof); + + LinearAlgebra::distributed::Vector vrefdouble; + LinearAlgebra::distributed::Vector vref; + AssertDimension(mgdof.n_dofs(tr.n_global_levels()-1), mgdof.n_dofs()); + vrefdouble.reinit(mgdof.n_dofs()); + VectorTools::interpolate(mgdof, Functions::Monomial(exponents_monomial, dim), vrefdouble); + + vref.reinit(mgdof.n_dofs()); + vref = vrefdouble; + std::vector > vec(tr.n_global_levels()); + for (unsigned int level=0; level::epsilon(); + deallog << "Error after prolongation: " + << filter_out_small_numbers(vec.back().linfty_norm(), tolerance) << std::endl; + + // unfortunately, no completely trivial expression of what should happen + // during restriction + vec.back() = vref; + for (unsigned int level=tr.n_global_levels()-1; level > 0 ; --level) + transfer.restrict_and_add(level, vec[level-1], vec[level]); + deallog << "Norm after restriction: " << vec[0].l2_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>(3)); + check<2,double>(FE_DGQ<2>(8)); + check<2,double>(FE_DGQ<2>(16)); + check<2,double>(FE_Q<2>(16)); + check<3,double>(FE_DGQ<3>(11)); + check<2,float> (FE_DGQ<2>(3)); + check<2,float> (FE_DGQ<2>(8)); + check<2,float> (FE_DGQ<2>(16)); + check<2,float> (FE_Q<2>(16)); + check<3,float> (FE_DGQ<3>(11)); +} diff --git a/tests/multigrid/transfer_matrix_free_12.output b/tests/multigrid/transfer_matrix_free_12.output new file mode 100644 index 0000000000..b3cf0ec67f --- /dev/null +++ b/tests/multigrid/transfer_matrix_free_12.output @@ -0,0 +1,41 @@ + +DEAL::FE: FESystem<2>[FE_DGQ<2>(3)^2] +DEAL::no. cells: 16 +DEAL::Error after prolongation: 0.00000 +DEAL::Norm after restriction: 48.2543 +DEAL::FE: FESystem<2>[FE_DGQ<2>(8)^2] +DEAL::no. cells: 16 +DEAL::Error after prolongation: 0.00000 +DEAL::Norm after restriction: 101.354 +DEAL::FE: FESystem<2>[FE_DGQ<2>(16)^2] +DEAL::no. cells: 16 +DEAL::Error after prolongation: 0.00000 +DEAL::Norm after restriction: 214.405 +DEAL::FE: FESystem<2>[FE_Q<2>(16)^2] +DEAL::no. cells: 16 +DEAL::Error after prolongation: 0.00000 +DEAL::Norm after restriction: 189.129 +DEAL::FE: FESystem<3>[FE_DGQ<3>(11)^3] +DEAL::no. cells: 64 +DEAL::Error after prolongation: 0.00000 +DEAL::Norm after restriction: 1340.82 +DEAL::FE: FESystem<2>[FE_DGQ<2>(3)^2] +DEAL::no. cells: 16 +DEAL::Error after prolongation: 0.00000 +DEAL::Norm after restriction: 48.2544 +DEAL::FE: FESystem<2>[FE_DGQ<2>(8)^2] +DEAL::no. cells: 16 +DEAL::Error after prolongation: 0.00000 +DEAL::Norm after restriction: 101.354 +DEAL::FE: FESystem<2>[FE_DGQ<2>(16)^2] +DEAL::no. cells: 16 +DEAL::Error after prolongation: 0.00000 +DEAL::Norm after restriction: 214.405 +DEAL::FE: FESystem<2>[FE_Q<2>(16)^2] +DEAL::no. cells: 16 +DEAL::Error after prolongation: 0.00000 +DEAL::Norm after restriction: 189.129 +DEAL::FE: FESystem<3>[FE_DGQ<3>(11)^3] +DEAL::no. cells: 64 +DEAL::Error after prolongation: 0.00000 +DEAL::Norm after restriction: 1340.82 -- 2.39.5