My Project
mod_tridiag.f90
Go to the documentation of this file.
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 !/===========================================================================/
13 ! CVS VERSION INFORMATION
14 ! $Id$
15 ! $Name$
16 ! $Revision$
17 !/===========================================================================/
18 
19 !-----------------------------------------------------------------------
20 !BOP
21 !
22 ! !MODULE: mtridiagonal --- solver for tri-diagonal matrices \label{sec:tridiagonal}
23 !
24 ! !INTERFACE:
26  use mod_prec
27 !
28 ! !DESCRIPTION:
29 !
30 ! Solves a linear system of equations with a tridiagonal matrix
31 ! using Gaussian elimination.
32 !
33 ! !PUBLIC MEMBER FUNCTIONS:
34  public init_tridiagonal,tridiagonal
35 !
36 ! !PUBLIC DATA MEMBERS:
37  real(sp), dimension(:), allocatable :: au,bu,cu,du
38 !
39 ! !REVISION HISTORY:
40 ! Original author(s): Hans Burchard & Karsten Bolding
41 ! $Log$
42 ! Revision 1.2 2010/07/19 22:34:00 gcowles
43 ! modified to avoid namespace overlap with gotm libraries
44 !
45 ! Revision 1.1.1.1 2010/01/03 19:36:17 jqi
46 !
47 !
48 ! Revision 1.2.2.3 2008/07/16 18:48:53 dstuebe
49 ! added new header and copyright info
50 !
51 ! Revision 1.2.2.2 2008/04/03 17:03:48 dstuebe
52 ! Changed Header
53 !
54 ! Revision 1.2.2.1 2007/12/26 18:02:14 dstuebe
55 ! added cvs keyword tags
56 !
57 ! Revision 1.2 2007/02/28 21:40:05 dstuebe
58 ! Added comments about ICE
59 !
60 ! Revision 1.1.1.1 2007/02/28 19:48:18 dstuebe
61 ! Import of Gao's Ice model
62 !
63 ! Revision 1.1 2006/06/20 00:14:52 gcowles
64 ! *** empty log message ***
65 !
66 ! Revision 1.4 2003/03/28 09:20:36 kbk
67 ! added new copyright to files
68 !
69 ! Revision 1.3 2003/03/28 08:06:33 kbk
70 ! removed tabs
71 !
72 ! Revision 1.2 2003/03/10 08:54:16 gotm
73 ! Improved documentation and cleaned up code
74 !
75 ! Revision 1.1.1.1 2001/02/12 15:55:58 gotm
76 ! initial import into CVS
77 !
78 !EOP
79 !
80 ! private data members
81  real(sp), private, dimension(:),allocatable :: ru,qu
82 !
83 !-----------------------------------------------------------------------
84 
85  contains
86 
87 !-----------------------------------------------------------------------
88 !BOP
89 !
90 ! !IROUTINE: Allocate memory
91 !
92 ! !INTERFACE:
93  subroutine init_tridiagonal_scal(N)
94 !
95 ! !DESCRIPTION:
96 ! This routines allocates memory necessary to perform the Gaussian
97 ! elimination.
98 !
99 ! !USES:
100  IMPLICIT NONE
101 !
102 ! !INPUT PARAMETERS:
103  integer, intent(in) :: N
104 !
105 ! !REVISION HISTORY:
106 ! Original author(s): Hans Burchard & Karsten Bolding
107 !
108 !EOP
109 !
110 !
111 !-----------------------------------------------------------------------
112 !BOC
113  if(allocated(au))then
114  deallocate(au)
115  deallocate(bu)
116  deallocate(cu)
117  deallocate(du)
118  deallocate(ru)
119  deallocate(qu)
120  endif
121 
122  allocate(au(0:n)) ; au = 0.
123  allocate(bu(0:n)) ; bu = 0.
124  allocate(cu(0:n)) ; cu = 0.
125  allocate(du(0:n)) ; du = 0.
126  allocate(ru(0:n)) ; ru = 0.
127  allocate(qu(0:n)) ; qu = 0.
128 
129  return
130  end subroutine init_tridiagonal_scal
131 !EOC
132 
133 !-----------------------------------------------------------------------
134 !BOP
135 !
136 ! !IROUTINE: Simplified Gaussian elimination
137 !
138 ! !INTERFACE:
139  subroutine tridiagonal_scal(N,fi,lt,value)
140 !
141 ! !DESCRIPTION:
142 ! A linear equation with tridiagonal matrix is solved here. The main
143 ! diagonal is stored on {\tt bu}, the upper diagonal on {\tt au}, and the
144 ! lower diagonal on {\tt cu}, the right hand side is stored on {\tt du}.
145 ! The method used here is the simplified Gauss elimination, also called
146 ! \emph{Thomas algorithm}.
147 !
148 ! !USES:
149  IMPLICIT NONE
150 !
151 ! !INPUT PARAMETERS:
152  integer, intent(in) :: N,fi,lt
153 !
154 ! !OUTPUT PARAMETERS:
155  real(sp) :: value(0:N)
156 !
157 ! !REVISION HISTORY:
158 ! Original author(s): Hans Burchard & Karsten Bolding
159 ! $Log$
160 ! Revision 1.2 2010/07/19 22:34:00 gcowles
161 ! modified to avoid namespace overlap with gotm libraries
162 !
163 ! Revision 1.1.1.1 2010/01/03 19:36:17 jqi
164 !
165 !
166 ! Revision 1.2.2.3 2008/07/16 18:48:53 dstuebe
167 ! added new header and copyright info
168 !
169 ! Revision 1.2.2.2 2008/04/03 17:03:48 dstuebe
170 ! Changed Header
171 !
172 ! Revision 1.2.2.1 2007/12/26 18:02:14 dstuebe
173 ! added cvs keyword tags
174 !
175 ! Revision 1.2 2007/02/28 21:40:05 dstuebe
176 ! Added comments about ICE
177 !
178 ! Revision 1.1.1.1 2007/02/28 19:48:18 dstuebe
179 ! Import of Gao's Ice model
180 !
181 ! Revision 1.1 2006/06/20 00:14:52 gcowles
182 ! *** empty log message ***
183 !
184 ! Revision 1.4 2003/03/28 09:20:36 kbk
185 ! added new copyright to files
186 !
187 ! Revision 1.3 2003/03/28 08:06:33 kbk
188 ! removed tabs
189 !
190 ! Revision 1.2 2003/03/10 08:54:16 gotm
191 ! Improved documentation and cleaned up code
192 !
193 ! Revision 1.1.1.1 2001/02/12 15:55:58 gotm
194 ! initial import into CVS
195 !
196 !EOP
197 !
198 ! !LOCAL VARIABLES:
199  integer :: i
200 !
201 !-----------------------------------------------------------------------
202 !BOC
203  ru(lt)=au(lt)/bu(lt)
204  qu(lt)=du(lt)/bu(lt)
205 
206  do i=lt-1,fi+1,-1
207  ru(i)=au(i)/(bu(i)-cu(i)*ru(i+1))
208  qu(i)=(du(i)-cu(i)*qu(i+1))/(bu(i)-cu(i)*ru(i+1))
209  end do
210 
211  qu(fi)=(du(fi)-cu(fi)*qu(fi+1))/(bu(fi)-cu(fi)*ru(fi+1))
212 
213  value(fi)=qu(fi)
214  do i=fi+1,lt
215  value(i)=qu(i)-ru(i)*value(i-1)
216  end do
217 
218 
219  return
220  end subroutine tridiagonal_scal
221 !EOC
222 
223 !-----------------------------------------------------------------------
224 
225  end module mtridiagonal_scal
226 
227 !-----------------------------------------------------------------------
228 ! Copyright by the GOTM-team under the GNU Public License - www.gnu.org
229 !-----------------------------------------------------------------------
subroutine tridiagonal_scal(N, fi, lt, value)
real(sp), dimension(:), allocatable bu
Definition: mod_tridiag.f90:37
real(sp), dimension(:), allocatable cu
Definition: mod_tridiag.f90:37
subroutine init_tridiagonal_scal(N)
Definition: mod_tridiag.f90:94
real(sp), dimension(:), allocatable du
Definition: mod_tridiag.f90:37
integer, parameter sp
Definition: mod_prec.f90:48
real(sp), dimension(:), allocatable au
Definition: mod_tridiag.f90:37