CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Wiki > TDMA 11.f90 - Solution of system of linear equatrions by Thoma...

TDMA 11.f90 - Solution of system of linear equatrions by Thomas method

From CFD-Wiki

Jump to: navigation, search

!Sample program for solving Smith-Hutton Test using different schemes 
!of covective terms approximation -  TDMA algorithm modul
!Copyright (C) 2005  Michail Kirichkov

!This program is free software; you can redistribute it and/or
!modify it under the terms of the GNU General Public License
!as published by the Free Software Foundation; either version 2
!of the License, or (at your option) any later version.

!This program is distributed in the hope that it will be useful,
!but WITHOUT ANY WARRANTY; without even the implied warranty of
!MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
!GNU General Public License for more details.

!You should have received a copy of the GNU General Public License
!along with this program; if not, write to the Free Software
!Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

!***************************************************************************

Subroutine TDMA_1(NF)

include 'icomm_1.f90'  

Dimension P(nx),Q(nx)

!--------------------------------------------------------------------------------------------------------------------------------------------------------
!--------------------------------------------------------------------------------------------------------------------------------------------------------
!--------------------------------------------------------------------------------------------------------------------------------------------------------

	Do 101 J =  2, NYmax
          			        P(1) =  0.		    
					Q(1) =  F(1,j,nf)   
					P(NXmaxP) = 0.
					Q(NXmaxP) = F(NXmaxP,j,nf) 
 !		Forward Elimination

	      Do 10 i = 2,NXmaxP-1
			
			temp =  Ap(i,j) - Aw(i,j) * P(i-1)
	
 			 Spp= Sp(i,j) + As(i,j) * F(i,j-1,nf) + &
 				        An(i,j) * F(i,j+1,nf)  

					P(i) = Ae(i,j) / temp
			        
        	          Q(i) = (Spp + Aw(i,j)*Q(i-1)) / temp

		10    continue

!		 Back Substitution
      
	  Do 20 i = NXmaxP-1,1,-1

          F(i,j,nf) = P(i)*F(i+1,j,nf) + Q(i)
	
		20    continue
 
     101 continue 
!--------------------------------------------------------------------------------------------------------------------------------------------------------
!--------------------------------------------------------------------------------------------------------------------------------------------------------

	Do 301 J =  NYmax,2,-1

			 	        P(1) =  0.		    
					Q(1) =  F(1,j,nf)   
					P(NXmaxP) = 0.
					Q(NXmaxP) = F(NXmaxP,j,nf) 

 !		Forward Elimination

	      Do 32 i = 2,NXmaxP-1
			
			temp =  Ap(i,j) - Aw(i,j) * P(i-1)
	
			Spp= Sp(i,j) + As(i,j) * F(i,j-1,nf) + &
			               An(i,j) * F(i,j+1,nf)  

					P(i) = Ae(i,j) / temp
			                Q(i) = (Spp + Aw(i,j)*Q(i-1)) / temp
		32    continue

!		 Back Substitution
      
	  Do 30 i = NXmaxP-1,2,-1

         F(i,j,nf) = P(i)*F(i+1,j,nf) + Q(i)
	
		30    continue
 
     301 continue 

!--------------------------------------------------------------------------------------------------------------------------------------------------------

!--------------------------------------------------------------------------------------------------------------------------------------------------------

	Do 201 I =  NXmax,2,-1 

 		 	                P(1) =  0.		    
					Q(1) =  F(i,1,nf)   
					P(NYmaxP) = 0.
					Q(NYmaxP) = F(i,NYmaxP,nf) 

 !		Forward Elimination

	      Do 14 j = 2,NYmaxP-1
			
			temp =  Ap(i,j) - As(i,j) * P(j-1)
	
			Spp= Sp(i,j) + Aw(i,j) * F(i-1,j,nf) + &
				       Ae(i,j) * F(i+1,j,nf)  

					P(j) = An(i,j) / temp
			        	Q(j) = (Spp - As(i,j)*Q(j-1)) / temp
		14    continue

!		 Back Substitution
      
	  Do 22 j = NYmaxP-1,2,-1
 
 !       F(i,j,nf) = P(j)*F(i,j+1,nf) + Q(j)
	
		22    continue
 
     201 continue 

!-------------------------------------------------------------------------------------------------------------------------------------------------------- 

!--------------------------------------------------------------------------------------------------------------------------------------------------------

	Do 211 I =  2,NXmax 

			 	        P(1) =  0.		    
					Q(1) =  F(i,1,nf)   
					P(NYmaxP) = 0.
					Q(NYmaxP) = F(i,NYmaxP,nf) 

 !		Forward Elimination

	      Do 15 j = 2,NYmaxP-1
			
			temp =  Ap(i,j) - As(i,j) * P(j-1)
 		
	          Spp= Sp(i,j) + Aw(i,j) * F(i-1,j,nf) + &
			         Ae(i,j) * F(i+1,j,nf)  

		 	P(j) = An(i,j) / temp
			        
 			Q(j) = (Spp - As(i,j)*Q(j-1)) / temp

		15    continue

!		 Back Substitution
      
	  Do 23 j = NYmaxP-1,2,-1

 !      F(i,j,nf) = P(j)*F(i,j+1,nf) + Q(j)
	
		23   continue
 
     211 continue 

!-------------------------------------------------------------------------------------------------------------------------------------------------------- 

Return
End
My wiki