00001 // This file is part of ff3d - http://www.freefem.org/ff3d 00002 // Copyright (C) 2001, 2002, 2003 Stéphane Del Pino 00003 00004 // This program is free software; you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation; either version 2, or (at your option) 00007 // any later version. 00008 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, write to the Free Software Foundation, 00016 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 00018 // $Id: DiagPrecond.hpp,v 1.4 2007/05/20 23:02:49 delpinux Exp $ 00019 00020 00021 // This is very simple preconditioner: Diagonale of Operator. 00022 00023 #ifndef _DIAGPRECOND_HPP_ 00024 #define _DIAGPRECOND_HPP_ 00025 00026 #include <TinyVector.hpp> 00027 #include <TinyMatrix.hpp> 00028 #include <Vector.hpp> 00029 #include <Preconditioner.hpp> 00030 00038 class DiagPrecond 00039 : public Preconditioner 00040 { 00041 private: 00043 Vector<real_t> P; 00044 00046 const BaseMatrix& A; 00047 public: 00048 00049 std::string name() const 00050 { 00051 return "diagonal"; 00052 } 00053 00055 void initializes() 00056 { 00057 Vector<real_t> diagonal(A.size()); 00058 A.getDiagonal(diagonal); 00059 for (size_t i=0; i<A.size(); ++i) { 00060 if (diagonal[i] != 0) 00061 P[i] = 1./diagonal[i]; 00062 else 00063 P[i] = 1.; 00064 } 00065 } 00066 00068 void computes(const Vector<real_t>& r , 00069 Vector<real_t>& z) const 00070 { 00071 ASSERT ((P.size() == r.size())&&(P.size() == z.size())); 00072 for (size_t i=0; i<P.size(); ++i) { 00073 z[i] = P[i]*r[i]; 00074 } 00075 } 00076 00078 DiagPrecond(const DiagPrecond& D) 00079 : Preconditioner(D), 00080 P(D.P), 00081 A(D.A) 00082 { 00083 ; 00084 } 00085 00087 DiagPrecond(const Problem& Pb, 00088 const BaseMatrix& AA) 00089 : Preconditioner(Pb, diagonale), 00090 P(AA.size()), 00091 A(AA) 00092 { 00093 ; 00094 } 00095 00097 ~DiagPrecond() 00098 { 00099 ; 00100 } 00101 }; 00102 00103 #endif // _DIAGPRECOND_HPP_ 00104
1.5.6