From: kanschat Date: Fri, 20 May 2011 02:07:54 +0000 (+0000) Subject: verify consistency of block relaxation and block preconditiioning methods X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=06a67ada9e1bfdae4b522ef85d079d41889b200b;p=dealii-svn.git verify consistency of block relaxation and block preconditiioning methods git-svn-id: https://svn.dealii.org/trunk@23728 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/tests/lac/solver_relaxation_01.cc b/tests/lac/solver_relaxation_01.cc index 36aae8a74d..b5a680f11c 100644 --- a/tests/lac/solver_relaxation_01.cc +++ b/tests/lac/solver_relaxation_01.cc @@ -1,7 +1,7 @@ //---------------------------------------------------------------------- // $Id$ // -// Copyright (C) 1998 - 2005, 2010 by the deal.II authors +// Copyright (C) 1998 - 2005, 2010, 2011 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -48,7 +48,8 @@ check_solve( SOLVER& solver, const MATRIX& A, int main() { - std::ofstream logfile("solver_relaxation_01/output"); + const std::string logname = JobIdentifier::base_name(__FILE__) + std::string("/output"); + std::ofstream logfile(logname.c_str()); // logfile.setf(std::ios::fixed); deallog << std::setprecision(4); deallog.attach(logfile); diff --git a/tests/lac/solver_relaxation_02.cc b/tests/lac/solver_relaxation_02.cc new file mode 100644 index 0000000000..2f36510403 --- /dev/null +++ b/tests/lac/solver_relaxation_02.cc @@ -0,0 +1,153 @@ +//---------------------------------------------------------------------- +// $Id$ +// +// Copyright (C) 2011 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. +// +//---------------------------------------------------------------------- + +// Compare preconditioned Richardson with block relaxation. All output diffs +// should be zero. + +#include "../tests.h" +#include "testmatrix.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +template +double +check_solve( SOLVER& solver, const MATRIX& A, + VECTOR& u, VECTOR& f, const PRECONDITION& P) +{ + double result = 0.; + u = 0.; + f = 1.; + try + { + solver.solve(A,u,f,P); + } + catch (SolverControl::NoConvergence& e) + { + result = e.last_residual; + } + return result; +} + +int main() +{ + const std::string logname = JobIdentifier::base_name(__FILE__) + std::string("/output"); + std::ofstream logfile(logname.c_str()); +// logfile.setf(std::ios::fixed); + deallog << std::setprecision(4); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + SolverControl control(100, 1.e-3); + SolverRichardson<> rich(control); + SolverRelaxation<> relax(control); + + for (unsigned int size=33; size <= 33; size *= 3) + { + unsigned int dim = (size-1)*(size-1); + + deallog << "Size " << size << " Unknowns " << dim << std::endl; + + // Make matrix + FDMatrix testproblem(size, size); + SparsityPattern structure(dim, dim, 5); + testproblem.five_point_structure(structure); + structure.compress(); + SparseMatrix A(structure); + testproblem.five_point(A); + + for (unsigned int blocksize = 2; blocksize < 32; blocksize <<= 1) + { + deallog << "Block size " << blocksize << std::endl; + + const unsigned int n_blocks = dim/blocksize; + BlockList blist; + blist.initialize(n_blocks); + std::vector indices(blocksize); + + for (unsigned int block=0;block,double>::AdditionalData relax_data(blist, 0.8); + PreconditionBlock,double>::AdditionalData prec_data(blocksize, 0.8); + + PreconditionBlockJacobi,double> prec_jacobi; + prec_jacobi.initialize(A, prec_data); + PreconditionBlockSOR,double> prec_sor; + prec_sor.initialize(A, prec_data); + PreconditionBlockSSOR,double> prec_ssor; + prec_ssor.initialize(A, prec_data); + + RelaxationBlockJacobi,double> relax_jacobi; + relax_jacobi.initialize(A, relax_data); + RelaxationBlockSOR,double> relax_sor; + relax_sor.initialize(A, relax_data); + RelaxationBlockSSOR,double> relax_ssor; + relax_ssor.initialize(A, relax_data); + + Vector f(dim); + Vector u(dim); + Vector res(dim); + + f = 1.; + u = 1.; + + try + { + double r1, r2; + + deallog.push("Jacobi"); + r1 = check_solve(rich,A,u,f,prec_jacobi); + r2 = check_solve(relax,A,u,f,prec_jacobi); + deallog << "diff " << std::fabs(r1-r2)/r1 << std::endl; + r2 = check_solve(relax,A,u,f,relax_jacobi); + deallog << "diff " << std::fabs(r1-r2)/r1 << std::endl; + deallog.pop(); + + deallog.push("SOR "); + r1 = check_solve(rich,A,u,f,prec_sor); + r2 = check_solve(relax,A,u,f,prec_sor); + deallog << "diff " << std::fabs(r1-r2)/r1 << std::endl; + r2 = check_solve(relax,A,u,f,relax_sor); + deallog << "diff " << std::fabs(r1-r2)/r1 << std::endl; + deallog.pop(); + + deallog.push("SSOR "); + r1 = check_solve(rich,A,u,f,prec_ssor); + r2 = check_solve(relax,A,u,f,prec_ssor); + deallog << "diff " << std::fabs(r1-r2)/r1 << std::endl; + r2 = check_solve(relax,A,u,f,relax_ssor); + deallog << "diff " << std::fabs(r1-r2)/r1 << std::endl; + deallog.pop(); + } + catch (std::exception& e) + { + std::cerr << "Exception: " << e.what() << std::endl; + } + } + } +} + diff --git a/tests/lac/solver_relaxation_02/cmp/generic b/tests/lac/solver_relaxation_02/cmp/generic new file mode 100644 index 0000000000..1f0ca05ed8 --- /dev/null +++ b/tests/lac/solver_relaxation_02/cmp/generic @@ -0,0 +1,102 @@ + +DEAL::Size 33 Unknowns 1024 +DEAL::Block size 2 +DEAL:Jacobi:Richardson::Starting value 32.00 +DEAL:Jacobi:Richardson::Failure step 100 value 16.51 +DEAL:Jacobi:Relaxation::Starting value 32.00 +DEAL:Jacobi:Relaxation::Failure step 100 value 16.51 +DEAL:Jacobi::diff 0 +DEAL:Jacobi:Relaxation::Starting value 32.00 +DEAL:Jacobi:Relaxation::Failure step 100 value 16.51 +DEAL:Jacobi::diff 0 +DEAL:SOR :Richardson::Starting value 32.00 +DEAL:SOR :Richardson::Failure step 100 value 12.27 +DEAL:SOR :Relaxation::Starting value 32.00 +DEAL:SOR :Relaxation::Failure step 100 value 12.27 +DEAL:SOR ::diff 0 +DEAL:SOR :Relaxation::Starting value 32.00 +DEAL:SOR :Relaxation::Failure step 100 value 12.27 +DEAL:SOR ::diff 0 +DEAL:SSOR :Richardson::Starting value 32.00 +DEAL:SSOR :Richardson::Failure step 100 value 5.660 +DEAL:SSOR :Relaxation::Starting value 32.00 +DEAL:SSOR :Relaxation::Failure step 100 value 5.660 +DEAL:SSOR ::diff 0 +DEAL:SSOR :Relaxation::Starting value 32.00 +DEAL:SSOR :Relaxation::Failure step 100 value 5.660 +DEAL:SSOR ::diff 0 +DEAL::Block size 4 +DEAL:Jacobi:Richardson::Starting value 32.00 +DEAL:Jacobi:Richardson::Failure step 100 value 15.27 +DEAL:Jacobi:Relaxation::Starting value 32.00 +DEAL:Jacobi:Relaxation::Failure step 100 value 15.27 +DEAL:Jacobi::diff 0 +DEAL:Jacobi:Relaxation::Starting value 32.00 +DEAL:Jacobi:Relaxation::Failure step 100 value 15.27 +DEAL:Jacobi::diff 0 +DEAL:SOR :Richardson::Starting value 32.00 +DEAL:SOR :Richardson::Failure step 100 value 10.60 +DEAL:SOR :Relaxation::Starting value 32.00 +DEAL:SOR :Relaxation::Failure step 100 value 10.60 +DEAL:SOR ::diff 0 +DEAL:SOR :Relaxation::Starting value 32.00 +DEAL:SOR :Relaxation::Failure step 100 value 10.60 +DEAL:SOR ::diff 0 +DEAL:SSOR :Richardson::Starting value 32.00 +DEAL:SSOR :Richardson::Failure step 100 value 4.196 +DEAL:SSOR :Relaxation::Starting value 32.00 +DEAL:SSOR :Relaxation::Failure step 100 value 4.196 +DEAL:SSOR ::diff 0 +DEAL:SSOR :Relaxation::Starting value 32.00 +DEAL:SSOR :Relaxation::Failure step 100 value 4.196 +DEAL:SSOR ::diff 0 +DEAL::Block size 8 +DEAL:Jacobi:Richardson::Starting value 32.00 +DEAL:Jacobi:Richardson::Failure step 100 value 14.29 +DEAL:Jacobi:Relaxation::Starting value 32.00 +DEAL:Jacobi:Relaxation::Failure step 100 value 14.29 +DEAL:Jacobi::diff 0 +DEAL:Jacobi:Relaxation::Starting value 32.00 +DEAL:Jacobi:Relaxation::Failure step 100 value 14.29 +DEAL:Jacobi::diff 0 +DEAL:SOR :Richardson::Starting value 32.00 +DEAL:SOR :Richardson::Failure step 100 value 9.455 +DEAL:SOR :Relaxation::Starting value 32.00 +DEAL:SOR :Relaxation::Failure step 100 value 9.455 +DEAL:SOR ::diff 0 +DEAL:SOR :Relaxation::Starting value 32.00 +DEAL:SOR :Relaxation::Failure step 100 value 9.455 +DEAL:SOR ::diff 0 +DEAL:SSOR :Richardson::Starting value 32.00 +DEAL:SSOR :Richardson::Failure step 100 value 3.335 +DEAL:SSOR :Relaxation::Starting value 32.00 +DEAL:SSOR :Relaxation::Failure step 100 value 3.335 +DEAL:SSOR ::diff 0 +DEAL:SSOR :Relaxation::Starting value 32.00 +DEAL:SSOR :Relaxation::Failure step 100 value 3.335 +DEAL:SSOR ::diff 0 +DEAL::Block size 16 +DEAL:Jacobi:Richardson::Starting value 32.00 +DEAL:Jacobi:Richardson::Failure step 100 value 13.60 +DEAL:Jacobi:Relaxation::Starting value 32.00 +DEAL:Jacobi:Relaxation::Failure step 100 value 13.60 +DEAL:Jacobi::diff 0 +DEAL:Jacobi:Relaxation::Starting value 32.00 +DEAL:Jacobi:Relaxation::Failure step 100 value 13.60 +DEAL:Jacobi::diff 0 +DEAL:SOR :Richardson::Starting value 32.00 +DEAL:SOR :Richardson::Failure step 100 value 8.752 +DEAL:SOR :Relaxation::Starting value 32.00 +DEAL:SOR :Relaxation::Failure step 100 value 8.752 +DEAL:SOR ::diff 0 +DEAL:SOR :Relaxation::Starting value 32.00 +DEAL:SOR :Relaxation::Failure step 100 value 8.752 +DEAL:SOR ::diff 0 +DEAL:SSOR :Richardson::Starting value 32.00 +DEAL:SSOR :Richardson::Failure step 100 value 2.874 +DEAL:SSOR :Relaxation::Starting value 32.00 +DEAL:SSOR :Relaxation::Failure step 100 value 2.874 +DEAL:SSOR ::diff 0 +DEAL:SSOR :Relaxation::Starting value 32.00 +DEAL:SSOR :Relaxation::Failure step 100 value 2.874 +DEAL:SSOR ::diff 0