From 23f98ef4a224641c0fbf5611b4b3b243a2dbda6e Mon Sep 17 00:00:00 2001 From: Timo Heister Date: Mon, 17 Jan 2011 18:11:19 +0000 Subject: [PATCH] PETSc test for Precondition*::vmult() git-svn-id: https://svn.dealii.org/trunk@23206 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/petsc/solver_13.cc | 96 +++++++++++++++++++++++++++++++ tests/petsc/solver_13/cmp/generic | 7 +++ 2 files changed, 103 insertions(+) create mode 100644 tests/petsc/solver_13.cc create mode 100644 tests/petsc/solver_13/cmp/generic diff --git a/tests/petsc/solver_13.cc b/tests/petsc/solver_13.cc new file mode 100644 index 0000000000..baa5679483 --- /dev/null +++ b/tests/petsc/solver_13.cc @@ -0,0 +1,96 @@ +//---------------------------- petsc_solver_13.cc --------------------------- +// $Id: solver_11.cc 20442 2010-01-25 10:46:00Z heister $ +// Version: $Name$ +// +// Copyright (C) 2004, 2005, 2010 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------- petsc_solver_13.cc --------------------------- + +// test the PETScWrapper::Precondition*::vmult + + +#include "../tests.h" +#include "../lac/testmatrix.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +template +void +check_solve( SOLVER& solver, const MATRIX& A, + VECTOR& u, VECTOR& f, const PRECONDITION& P) +{ + deallog << "Solver type: " << typeid(solver).name() << std::endl; + + solver.solve(A,u,f,P); + + deallog << "Solver stopped after " << solver.control().last_step() + << " iterations" << std::endl; +} + + +int main(int argc, char **argv) +{ + std::ofstream logfile("solver_13/output"); + deallog.attach(logfile); + deallog << std::setprecision(4); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + PetscInitialize(&argc,&argv,0,0); + { + SolverControl control(100, 1.e-3); + + const unsigned int size = 32; + unsigned int dim = (size-1)*(size-1); + + deallog << "Size " << size << " Unknowns " << dim << std::endl; + + // Make matrix + FDMatrix testproblem(size, size); + PETScWrappers::SparseMatrix A(dim, dim, 5); + testproblem.five_point(A); + + PETScWrappers::Vector f(dim); + PETScWrappers::Vector u(dim); + u = 0.; + f = 1.; + A.compress (); + f.compress (); + u.compress (); + PETScWrappers::Vector t=u; + + PETScWrappers::SolverPreOnly solver(control); + + PETScWrappers::PreconditionJacobi preconditioner(A); + + check_solve (solver, A,u,f, preconditioner); + + deallog << u.l2_norm() << std::endl; + + check_solve (solver, A,t,u, preconditioner); + + deallog << t.l2_norm() << std::endl; + + u = 0; + preconditioner.vmult(u, f); + deallog << u.l2_norm() << std::endl; + preconditioner.vmult(t, u); + deallog << t.l2_norm() << std::endl; + } + PetscFinalize (); +} + diff --git a/tests/petsc/solver_13/cmp/generic b/tests/petsc/solver_13/cmp/generic new file mode 100644 index 0000000000..2a67dabd0f --- /dev/null +++ b/tests/petsc/solver_13/cmp/generic @@ -0,0 +1,7 @@ + +DEAL::Size 32 Unknowns 961 +DEAL::Solver type: N6dealii13PETScWrappers10SolverLSQRE +DEAL::Starting value 31.00 +DEAL::Failure step 100 value 24.01 +DEAL::Iterative method reported convergence failure in step 100 with residual 24.0098 +DEAL::Solver stopped after 100 iterations -- 2.39.5