00001
00002
00003
00004
00005 !> @file
00006 !!
00007 !! Solution of a system of linear equations Ax=b with tridiagonal matrix A.
00008 !!
00009 !! @section Copyright
00010 !!
00011 !! Copyright 2010, 2011 Ralf Greve, Bjoern Grieger, Oliver J. Stenzel
00012 !!
00013 !! @section License
00014 !!
00015 !! This file is part of MAIC-2.
00016 !!
00017 !! MAIC-2 is free software: you can redistribute it and/or modify
00018 !! it under the terms of the GNU General Public License as published by
00019 !! the Free Software Foundation, either version 3 of the License, or
00020 !! (at your option) any later version.
00021 !!
00022 !! MAIC-2 is distributed in the hope that it will be useful,
00023 !! but WITHOUT ANY WARRANTY; without even the implied warranty of
00024 !! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00025 !! GNU General Public License for more details.
00026 !!
00027 !! You should have received a copy of the GNU General Public License
00028 !! along with MAIC-2. If not, see <http://www.gnu.org/licenses/>.
00029 !<
00030 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00031
00032
00033 !> Solution of a system of linear equations Ax=b with tridiagonal matrix A.
00034 !! @param[in] a0 a0(j) is element A_(j,j-1) of matrix A
00035 !! @param[in] a1 a1(j) is element A_(j,j) of matrix A
00036 !! @param[in] a2 a2(j) is element A_(j,j+1) of matrix A
00037 !! @param[in] b inhomogeneity vector
00038 !! @param[in] n_rows size of matrix A (indices run from 0 (!!!) to n_rows)
00039 !! @param[out] x solution vector.
00040 !<------------------------------------------------------------------------------
00041 subroutine tri_sle(a0, a1, a2, x, b, n_rows)
00042
00043 use maic2_types
00044
00045 implicit none
00046
00047 integer(i4b), intent(in) :: n_rows
00048 real(dp), dimension(0:*), intent(inout) :: a0, a1, a2, b
00049 real(dp), dimension(0:*), intent(out) :: x
00050
00051 integer(i4b) :: n
00052 real(dp), allocatable, dimension(:) :: help_x
00053
00054
00055
00056 do n=1, n_rows
00057 a1(n) = a1(n) - a0(n)/a1(n-1)*a2(n-1)
00058 end do
00059
00060 do n=1, n_rows
00061 b(n) = b(n) - a0(n)/a1(n-1)*b(n-1)
00062
00063
00064 end do
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 allocate(help_x(0:n_rows))
00075
00076 help_x(0) = b(n_rows)/a1(n_rows)
00077
00078 do n=1, n_rows
00079 help_x(n) = b(n_rows-n)/a1(n_rows-n) &
00080 -a2(n_rows-n)/a1(n_rows-n)*help_x(n-1)
00081 end do
00082
00083 do n=0, n_rows
00084 x(n) = help_x(n_rows-n)
00085 end do
00086
00087
00088
00089
00090 deallocate(help_x)
00091
00092
00093
00094
00095
00096 end subroutine tri_sle
00097