DOUG 0.2

FinePreconditioner_sgs.F90

Go to the documentation of this file.
00001 ! DOUG - Domain decomposition On Unstructured Grids
00002 ! Copyright (C) 1998-2006 Faculty of Computer Science, University of Tartu and
00003 ! Department of Mathematics, University of Bath
00004 !
00005 ! This library is free software; you can redistribute it and/or
00006 ! modify it under the terms of the GNU Lesser General Public
00007 ! License as published by the Free Software Foundation; either
00008 ! version 2.1 of the License, or (at your option) any later version.
00009 !
00010 ! This library is distributed in the hope that it will be useful,
00011 ! but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 ! Lesser General Public License for more details.
00014 !
00015 ! You should have received a copy of the GNU Lesser General Public
00016 ! License along with this library; if not, write to the Free Software
00017 ! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018 ! or contact the authors (University of Tartu, Faculty of Computer Science, Chair
00019 ! of Distributed Systems, Liivi 2, 50409 Tartu, Estonia, http://dougdevel.org,
00020 ! mailto:info(at)dougdevel.org)
00021 
00023 module FinePreconditioner_sgs_mod
00024   use Preconditioner_base_mod
00025   use stationary_mod
00026   use SpMtx_operation
00027 
00028   implicit none
00029 
00030 contains
00032   subroutine FinePreconditioner_sgs_Init(FP, n_iter)
00033     type(FinePreconditioner),intent(inout) :: FP
00034     integer,intent(in) :: n_iter !< number of iterations
00035 
00036     integer :: i
00037     type(SpMtx) :: A
00038     integer,pointer :: indi(:), indj(:)
00039     real(kind=rk),pointer :: val(:)
00040 
00041     FP%type = FINE_PRECONDITIONER_TYPE_SGS
00042 
00043     if (sctls%verbose>=1) then
00044       write(stream,"(A,I0,A)") "INFO: Sym. Gauss-Seidel preconditioner with ", n_iter," iterations"
00045     end if
00046 
00047     A = SpMtx_add(FP%distr%A,FP%distr%A_ghost,1.0_rk,1.0_rk)
00048 
00049     allocate(FP%sgs)
00050     FP%sgs%n_iter = n_iter
00051     allocate(FP%sgs%As(size(FP%domains%subd)))
00052     if (sctls%verbose>=2) write(stream,"(A,I0,A)") "INFO:  Initialize ", size(FP%sgs%As), " submatrices"
00053 
00054     do i=1,size(FP%sgs%As)
00055       call GetGivenElements(A,FP%domains%subd(i)%inds,indi,indj,val)
00056       FP%sgs%As(i) = SpMtx_NewInit(nnz=size(indi),nrows=A%nrows,ncols=A%ncols,&
00057            indi=indi,indj=indj,val=val)
00058       deallocate(indi,indj,val)
00059 
00060       if (sctls%verbose>=3) write(stream,"(A,I0,A)") "INFO:  Submatrix: ", FP%sgs%As(i)%nnz, " nonzeros"
00061     end do
00062 
00063     call SpMtx_destroy(A)
00064   end subroutine FinePreconditioner_sgs_Init
00065 
00067   subroutine FinePreconditioner_sgs_Apply(FP, sol, rhs)
00068     type(FinePreconditioner),intent(inout) :: FP
00069     real(kind=rk),dimension(:),pointer :: sol !< solution
00070     real(kind=rk),dimension(:),pointer :: rhs !< right hand side
00071 
00072     integer :: i
00073     real(kind=rk),allocatable :: tmp_sol(:)
00074 
00075     sol = 0
00076     allocate(tmp_sol(size(sol)))
00077     do i=1,size(FP%sgs%As)
00078       if (sctls%verbose>=4) &
00079            write(stream,"(A,I0,A)") "Debug SGS: Apply ", FP%sgs%As(i)%nnz, " elems"
00080       tmp_sol = 0
00081       call SymGaussSeidel(FP%sgs%As(i),tmp_sol,rhs,FP%sgs%n_iter)
00082       sol = sol+tmp_sol
00083     end do
00084     deallocate(tmp_sol)
00085   end subroutine FinePreconditioner_sgs_Apply
00086 
00087 end module FinePreconditioner_sgs_mod