// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- // vi: set et ts=4 sw=2 sts=2: /** \file \brief Test the preconditioners in the file `preconditioners.hh` */ #include #include #include #include #include #include #include namespace Dune { using Mat1 = BCRSMatrix>; using Mat2 = BCRSMatrix,1,1>>; using Vec1 = BlockVector>; using Vec2 = BlockVector,1>>; // explicit template instantiation of all preconditioners template class SeqJac; template class SeqSOR; template class SeqSSOR; template class Richardson; template class SeqDILU; template class SeqILU; template class SeqILDL; template class SeqJac; template class SeqSOR; template class SeqSSOR; template class Richardson; template class SeqDILU; template class SeqILU; template class SeqILDL; } // end namespace Dune using namespace Dune; template void setupProblem(Matrix& matrix, Vector& b) { int n=100; setupLaplacian(matrix,n); b.resize(n*n); Vector x(n*n); // Construct right-hand side such that '1' is the solution b=0; x=1; matrix.mv(x, b); } template void testPreconditioner(const Matrix& matrix, const Vector& b, Vector& x, Preconditioner& prec) { using Operator = MatrixAdapter; Operator linearOperator(matrix); InverseOperatorResult result; Dune::LoopSolver solver(linearOperator, prec, 1e-8,15,2); auto residual = b; solver.apply(x,residual,result); } template void testAllPreconditioners(const Matrix& matrix, const Vector& b) { Vector x = b; // Set the correct size x = 0; SeqSSOR seqSSOR(matrix, 1,1.0); testPreconditioner(matrix, b, x, seqSSOR); x = 0; SeqSOR seqSOR(matrix, 1,1.0); testPreconditioner(matrix, b, x, seqSOR); x = 0; SeqGS seqGS(matrix, 1,1.0); testPreconditioner(matrix, b, x, seqGS); x = 0; SeqJac seqJac(matrix, 1,1.0); testPreconditioner(matrix, b, x, seqJac); x = 0; SeqDILU seqDILU(matrix, 1.1); testPreconditioner(matrix, b, x, seqDILU); x = 0; SeqILU seqILU(matrix, 3, 1.2, true); testPreconditioner(matrix, b, x, seqILU); x = 0; Richardson richardson(1.5); testPreconditioner(matrix, b, x, richardson); x = 0; SeqILDL seqILDL(matrix, 1.2); testPreconditioner(matrix, b, x, seqILDL); } int main() try { { using Matrix = BCRSMatrix; using Vector = BlockVector; Matrix matrix; Vector b,x; setupProblem(matrix, b); testAllPreconditioners(matrix, b); } { using Matrix = BCRSMatrix >; using Vector = BlockVector >; Matrix matrix; Vector b,x; setupProblem(matrix, b); testAllPreconditioners(matrix, b); } return 0; } catch (std::exception& e) { std::cerr << e.what() << std::endl; return 1; }