Warning: this documentation for the development version is under construction.
00001 // Copyright (C) 2003-2009 Marc Duruflé 00002 // 00003 // This file is part of the linear-algebra library Seldon, 00004 // http://seldon.sourceforge.net/. 00005 // 00006 // Seldon is free software; you can redistribute it and/or modify it under the 00007 // terms of the GNU Lesser General Public License as published by the Free 00008 // Software Foundation; either version 2.1 of the License, or (at your option) 00009 // any later version. 00010 // 00011 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY 00012 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00013 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 00014 // more details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public License 00017 // along with Seldon. If not, see http://www.gnu.org/licenses/. 00018 00019 00020 #ifndef SELDON_FILE_PRECOND_SSOR_CXX 00021 00022 namespace Seldon 00023 { 00024 template <class T> 00025 class SorPreconditioner 00026 { 00027 protected : 00028 bool symmetric_precond; 00029 int nb_iter; 00030 T omega; 00031 00032 public : 00033 SorPreconditioner(); 00034 ~SorPreconditioner(){} 00035 00036 void InitSymmetricPreconditioning() { symmetric_precond = true; } 00037 void InitUnSymmetricPreconditioning() { symmetric_precond = false; } 00038 void SetParameterRelaxation(const T& param) { omega = param; } 00039 void SetNumberIterations(int nb_iterations) { nb_iter = nb_iterations; } 00040 00041 template<class Vector, class Matrix> 00042 void Solve(const Matrix& A, const Vector& r, Vector& z, 00043 bool init_guess_null = true); 00044 00045 template<class Vector, class Matrix> 00046 void TransSolve(const Matrix& A, const Vector& r, Vector& z, 00047 bool init_guess_null = true); 00048 00049 }; 00050 00051 00053 template<class T> 00054 SorPreconditioner<T>::SorPreconditioner() 00055 { 00056 nb_iter = 1; omega = T(1); 00057 symmetric_precond = true; 00058 } 00059 00060 00062 template<class T> 00063 template<class Vector, class Matrix> 00064 void SorPreconditioner<T>:: 00065 Solve(const Matrix& A, const Vector& r, Vector& z, bool init_guess_null) 00066 { 00067 if (init_guess_null) 00068 z.Zero(); 00069 00070 if (symmetric_precond) 00071 Seldon::SOR(A, z, r, omega, nb_iter, 0); 00072 else 00073 Seldon::SOR(A, z, r, omega, nb_iter, 2); 00074 } 00075 00076 00078 template<class T> 00079 template<class Vector, class Matrix> 00080 void SorPreconditioner<T>:: 00081 TransSolve(const Matrix& A, const Vector& r, Vector& z, bool init_guess_null) 00082 { 00083 if (init_guess_null) 00084 z.Zero(); 00085 00086 if (symmetric_precond) 00087 Seldon::SOR(A, z, r, omega, nb_iter, 0); 00088 else 00089 Seldon::SOR(A, z, r, omega, nb_iter, 3); 00090 } 00091 00092 } 00093 00094 #define SELDON_FILE_PRECOND_SSOR_CXX 00095 #endif