0% found this document useful (0 votes)
2K views7 pages

Fortran Programming - Heat Equation 2D SS NoGen (Elliptic PDE)

This document describes a program for solving the 2D steady-state heat equation on a rectangular plate with no internal heat generation. It defines variables for the temperature, geometry, material properties, and boundary conditions. It uses an implicit finite difference method to discretize the PDE and solve the system of equations iteratively until the temperature values converge within a specified error tolerance.

Uploaded by

Pedram Niakan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views7 pages

Fortran Programming - Heat Equation 2D SS NoGen (Elliptic PDE)

This document describes a program for solving the 2D steady-state heat equation on a rectangular plate with no internal heat generation. It defines variables for the temperature, geometry, material properties, and boundary conditions. It uses an implicit finite difference method to discretize the PDE and solve the system of equations iteratively until the temperature values converge within a specified error tolerance.

Uploaded by

Pedram Niakan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 7

PROGRAM HeatEquation_2D_SS_NoGen ! This program have been written by Pedram Niakan !_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-__-_-_-_-_-_-NOMENCLATOR_-_-_-_-_-_-_-__-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ !

T[i,j] ---> Temprature @ desired node(i,j) ! i,j ---> Respectively row & column of a node ((n-1)*(m-1)) ---> Number of cells ! m,n ---> Respectively number of rows & columns ! deltaX,deltaY ---> Respectively Length & Height of a cell ! BCS,BCW,BCN,BCS---> Boundry condidtions ! Tinf ---> Temprature of neighbor fluid For convection (@ Boundry) ! qe,qw,qn,qs ---> Heat Flux (@ Boundry) qe,qw,qn,qs<0 represents outgoing of heat from plate & ! cooling and qe,qw,qn,qs>0 represents incoming of heat in to the plate & heating ! k,h ---> Respectively conduction [watt/k-m] & convection [watt/k-m^2] coefficients ! probable ---> Probable values of temperature for solution of discreted equation ! !_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-__-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-__-_-__-_-_-_-_-_-_-_-_-_-_-_-_-_ IMPLICIT NONE REAL,ALLOCATABLE :: T(:,:),probable(:,:) INTEGER :: i,j,n,m,q,BCE,BCW,BCN,BCS REAL :: X,deltaX,Y,deltaY,k,h,er !-----------------------------------------DESCRIPTION-----------------------------------------------WRITE (*,*) "Discrete Equation for 2D,SS,NoGen Heat Transfer @ a rectangle plate:" WRITE (*,*) "" WRITE (*,*) " 2 2" WRITE (*,*) "T[i+1,j]+T[i-1,j] T[i,j+1]+T[i,j-1] (deltaX)+ (deltaY)" WRITE (*,*) "_________________ + _________________ = 2._________________ * T[i,j]" WRITE (*,*) " 2 2 2 2" WRITE (*,*) " (deltaX) (deltaY) (deltaX)*(deltaY)" WRITE (*,*) "" !---------------------------------------------------------------------------------------------------OPEN(1,FILE="INPUT(HeatEquation_2D_SS_NoGen).TXT",STATUS="REPLACE") OPEN(2,FILE="OUTPUT(HeatEquation_2D_SS_NoGen).TXT",STATUS="REPLACE") WRITE (*,*) "Please enter length of model @ X-Direction:"

READ (*,*) X WRITE (*,*) "Please enter number of Nodes @ X-Direction:" READ (*,*) n WRITE (*,*) "Please enter heigth of model @ Y-Direction:" READ (*,*) Y WRITE (*,*) "Please enter number of Nodes @ Y-Direction:" READ (*,*) m WRITE (*,*) "Enter thermophysics properties k[watt/kelv-m] & h [watt/kelv-m^2]:" READ (*,*) k,h deltaX=X/(n-1) deltaY=Y/(m-1) WRITE (*,*) "Enter allowed value for error:" READ (*,*) er ALLOCATE (T(1:n,1:m),probable(1:n,1:m)) !Declaration of probable values {0} for nodes DO i=1,n DO j=1,m T(i,j)=0 probable(i,j)=0 END DO END DO !DECLARATION OF BOUNDRY CONDITIONS q=0 !Declaration of boundry condition @ side E WRITE (*,*) "Declaration of boundry condition type @ side E:" WRITE (*,*) "" 10 WRITE (*,*)"Select one of below numbers:" WRITE (*,*)" 1 Temperatur" WRITE (*,*)" 2 Heat Flux" WRITE (*,*)" 3 Convection" READ (*,*) BCE !Declaration of boundry condition @ side W WRITE (*,*) "Declaration of boundry condition type @ side W:" WRITE (*,*) "" 20 WRITE (*,*)"Select one of below numbers:" WRITE (*,*)" 1 Temperatur" WRITE (*,*)" 2 Heat Flux" WRITE (*,*)" 3 Convection" READ (*,*) BCW !Declaration of boundry condition @ side N WRITE (*,*) "Declaration of boundry condition taype @ side N:"

WRITE (*,*) "" 30 WRITE (*,*)"Select one of below numbers:" WRITE (*,*)" 1 Temperatur" WRITE (*,*)" 2 Heat Flux" WRITE (*,*)" 3 Convection" READ (*,*) BCN !Declaration of boundry condition @ side S WRITE (*,*) "Declaration of boundry condition type @ side S:" WRITE (*,*) "" 40 WRITE (*,*)"Select one of below numbers:" WRITE (*,*)" 1 Temperatur" WRITE (*,*)" 2 Heat Flux" WRITE (*,*)" 3 Convection" READ (*,*) BCS

50 IF (BCE==1) THEN CALL Temperatur (q,n,m,BCE,BCW,BCN,BCS,T) ELSE IF (BCE==2) THEN CALL HeatFlux (q,n,deltaX,m,deltaY,k,BCE,BCW,BCN,BCS,T) ELSE IF (BCE==3) THEN CALL Convection (q,n,deltaX,m,deltaY,k,h,BCE,BCW,BCN,BCS,T) ELSE WRITE (*,*)"Enter a correct number for EAST!" GO TO 10 END IF 60 IF (BCW==1) THEN CALL Temperatur (q,n,m,BCE,BCW,BCN,BCS,T) ELSE IF (BCW==2) THEN CALL HeatFlux (q,n,deltaX,m,deltaY,k,BCE,BCW,BCN,BCS,T) ELSE IF (BCW==3) THEN CALL Convection (q,n,deltaX,m,deltaY,k,h,BCE,BCW,BCN,BCS,T) ELSE WRITE (*,*)"Enter a correct number for WEST!" GO TO 20 END IF 70 IF (BCN==1) THEN CALL Temperatur (q,n,m,BCE,BCW,BCN,BCS,T) ELSE IF (BCN==2) THEN CALL HeatFlux (q,n,deltaX,m,deltaY,k,BCE,BCW,BCN,BCS,T) ELSE IF (BCN==3) THEN CALL Convection (q,n,deltaX,m,deltaY,k,h,BCE,BCW,BCN,BCS,T) ELSE WRITE (*,*)"Enter a correct number for NORTH!" GO TO 30 END IF 80 IF (BCS==1) THEN CALL Temperatur (q,n,m,BCE,BCW,BCN,BCS,T) ELSE IF (BCS==2) THEN CALL HeatFlux (q,n,deltaX,m,deltaY,k,BCE,BCW,BCN,BCS,T)

ELSE IF (BCS==3) THEN CALL Convection (q,n,deltaX,m,deltaY,k,h,BCE,BCW,BCN,BCS,T) ELSE WRITE (*,*)"Enter a correct number for SOUTH!" GO TO 40 END IF !Using Try & Error method 90 DO i=2,n-1 DO j=2,m-1 T(i,j)=(((T(i+1,j)+T(i-1,j))/(deltaX**2))+((T(i,j+1)+T(i,j-1))/ (deltaY**2)))*(.5*(deltaX**2)*(deltaY**2)/(deltaX**2+deltaY**2)) WRITE (*,*) "T(",i,",",j,")=",T(i,j) q=1 END DO END DO DO i=2,n-1 DO j=2,m-1 IF (ABS(T(i,j)-probable(i,j))>er) THEN probable(i,j)=T(i,j) GO TO 50 END IF END DO END DO WRITE (2,*)"varibles:x,y" WRITE (2,*)"zone f=point,i=",n,",j=",m DO j=1,m DO i=1,n WRITE (*,*)"T(",i,",",j,")= ",T(i,j) WRITE (2,100)i,j,T(i,j) 100 FORMAT (15x,I10,I10,f20.6) END DO END DO PAUSE END PROGRAM HeatEquation_2D_SS_NoGen

! CONTAINS !------------------------------------------------------------------------------------------SUBROUTINE Temperatur (q,n,m,BCE,BCW,BCN,BCS,T) INTEGER,INTENT(IN):: q,n,m,BCE,BCW,BCN,BCS REAL :: Te,Tw,Tn,Ts INTEGER :: i,j REAL,DIMENSION(1:n,1:m),INTENT(INOUT) :: T IF (BCE==1) THEN IF (q==0) THEN WRITE (*,*) "Enter the Temperatur @ EAST SIDE:"

READ (*,*) Te END IF DO j=1,m T(n,j)=Te END DO END IF IF (BCW==1) THEN IF (q==0) THEN WRITE (*,*) "Enter the Temperatur @ WEST SIDE:" READ (*,*) Tw END IF DO j=1,m T(1,j)=Tw END DO END IF IF (BCN==1) THEN IF (q==0) THEN WRITE (*,*) "Enter the Temperatur @ NORTH SIDE:" READ (*,*) Tn END IF DO i=1,n T(i,m)=Tn END DO END IF IF (BCS==1) THEN IF (q==0) THEN WRITE (*,*) "Enter the Temperatur @ SOUTH SIDE:" READ (*,*) Ts END IF DO i=1,n T(i,1)=Ts END DO END IF RETURN END SUBROUTINE Temperatur

SUBROUTINE HeatFlux (q,n,deltaX,m,deltaY,k,BCE,BCW,BCN,BCS,T) INTEGER,INTENT(IN) :: q,n,m,BCE,BCW,BCN,BCS REAL,INTENT(IN) :: deltaX,deltaY,k INTEGER :: i,j REAL :: qe,qw,qn,qs REAL,DIMENSION(1:n,1:m),INTENT(INOUT) :: T IF (BCE==2) THEN IF (q==0) THEN WRITE (*,*) "Enter the HeatFlux @ EAST SIDE:"

READ (*,*) qe END IF DO j=1,m T(n,j)=qe*deltaX/k+T(n-1,j) END DO END IF IF (BCW==2) THEN IF (q==0) THEN WRITE (*,*) "Enter the HeatFlux @ WEST SIDE:" READ (*,*) qw END IF DO j=1,m T(1,j)=qw*deltaX/k+T(2,j) END DO END IF IF (BCN==2) THEN IF (q==0) THEN WRITE (*,*) "Enter the HeatFlux @ NORTH SIDE:" READ (*,*) qn END IF DO i=1,n T(i,m)=qn*deltaY/k+T(i,m-1) END DO END IF IF (BCS==2) THEN IF (q==0) THEN WRITE (*,*) "Enter the HeatFlux @ SOUTH SIDE:" READ (*,*) qs END IF DO i=1,n T(i,1)=qs*deltaY/k+T(i,2) END DO END IF RETURN END SUBROUTINE HeatFlux

SUBROUTINE Convection (q,n,deltaX,m,deltaY,k,h,BCE,BCW,BCN,BCS,T) INTEGER,INTENT(IN):: q,n,m,BCE,BCW,BCN,BCS REAL,INTENT(IN) :: deltaX,deltaY,k,h INTEGER :: i,j REAL :: Tinf_e,Tinf_w,Tinf_n,Tinf_s REAL,DIMENSION(1:n,1:m),INTENT(INOUT) :: T IF (BCE==3) THEN IF (q==0) THEN WRITE (*,*) "Enter the Tinf_e @ EAST SIDE:"

READ (*,*) Tinf_e END IF DO j=1,m T(n,j)=(T(n-1,j)+(h*deltaX/k)*Tinf_e)/(h*deltaX/k+1) END DO END IF IF (BCW==3) THEN IF (q==0) THEN WRITE (*,*) "Enter the Tinf_w @ WEST SIDE:" READ (*,*) Tinf_w END IF DO j=1,m T(1,j)=(T(2,j)+(h*deltaX/k)*Tinf_w)/(h*deltaX/k+1) END DO END IF IF (BCN==3) THEN IF (q==0) THEN WRITE (*,*) "Enter the Tinf_n @ NORTH SIDE:" READ (*,*) Tinf_n END IF DO i=1,n T(i,m)=(T(i,m-1)+(h*deltaX/k)*Tinf_n)/(h*deltaY/k+1) END DO END IF IF (BCS==3) THEN IF (q==0) THEN WRITE (*,*) "Enter the Tinf_s @ SOUTH SIDE:" READ (*,*) Tinf_s END IF DO i=1,n T(i,1)=(T(i,2)+(h*deltaX/k)*Tinf_s)/(h*deltaY/k+1) END DO END IF RETURN END SUBROUTINE Convection

You might also like