Sunteți pe pagina 1din 7

*12345678912345678912345678912345678912345678912345678912345678912345678

*
Two dimensional transient conduction program
*
Galerkin's finite element procedure
*
fully explicit form
*
written and modified by P. Nithiarasu, Nov. 2000
*
warning: some of the parametrs may not be used
***********************************************************************
program conduction
*
*
Main program
*
implicit double precision(a-h, o-z)
common/sol2/niter,idel,dtfix
parameter (np=5000,nel=10000,nbo=1000)
open(unit=11,file='input.dat')
open(unit=12,file='output.dat')
open(unit=13,file='restat.dat')
open(unit=14,file='bc.dat')
open(unit=15,file='bc.bco')
open(unit=16,file='par.dat')
call input(tt1,tt2,qflx,ibc)
write(*,*) 'input over'
call shape
write(*,*)'shape over'
call massmat
write(*,*)'massmat over'
call side
do i = 1,niter
nstep = nstep + i
time = time + dtfix
call right1
call right2(tt1,tt2,qflx,ibc)
istep = istep + 1
jk = mod(istep,100)
if(jk.eq.0)then
call error
call output
endif
enddo !i
write(*,*)'program stopped'
stop
end
*********************************************************************
Subroutine input(tt1,tt2,qflx,ibc)
*********************************************************************
*
* Reading input from 'input.dat'
*
implicit double precision(a-h, o-z)
parameter (np=5000,nel=10000,nbo=1000)
common/mesh1/npoin,nelem,nboud
common/mesh2/x(np),y(np),l(3,nel)
common/pro1/rho,cpp,thr1,thr2
common/sol1/theta1,theta2,theta3
common/sol2/niter,idel,dtfix

common/bon1/isid(4,nbo)
common/mas/dmat(np)
common/var/rhs(np),temp(np)
common/htin/htco,tinf
dimension ibc(nbo)
*
*
*

reading no. of elements, no. of nodes, band.wdth, restrt opt.


read(11,*)
read(11,*)npoin, nelem, nbw,iopt

*
*
*

reading x and y coordinates


read(11,*)
read(11,*)(ii,x(i),y(i),i=1,npoin)
read(11,*)

*
*
*

reading element connectivity


do ie = 1,nelem
read(11,*)iee,kk,(l(j,ie),j=1,3)
enddo !ie

*
*
*

reading boundary information


read(14,*)
read(14,*) nboud
read(14,*)
do i = 1, nboud
read(14,*)isid(1,i),isid(2,i),isid(3,i),isid(4,i)
enddo !i

*
*
*

reading from the boundary condition file


read(15,*)
read(15,*) nsec
read(15,*)
do i = 1, nsec
read(15,*)isec,ibco
do j = 1,nboud
if(isid(4,j).eq.isec)isid(4,j)=ibco
enddo !j
enddo !i

*
*
*

reading parameters
read(16,*)
read(16,*)
read(16,*)
read(16,*)

*
*
*
*

rho, cpp, thr1,thr2


theta1, theta2, theta3
niter,idel,dtfix
htco,tinf,tt1,tt2,qflx

re-start option, iopt = 0-start from scratch


rest start from a previous temperature field
if(iopt.eq.0)then
read(16,*)temi
do i = 1,npoin

temp(i) = temi
enddo
else
do i = 1,npoin
read(13,*)ii,temp(i)
enddo
endif
end
*********************************************************************
subroutine massmat
********************************************************************
*
*
Calculation of mass matrix
*
implicit double precision(a-h, o-z)
parameter (np=5000,nel=10000,nbo=1000)
common/mesh1/npoin,nelem,nboud
common/mesh2/x(np),y(np),l(3,nel)
common/pro1/rho,cpp,thr1,thr2
common/geom/geome(6,nel),area(nel)
common/mas/dmat(np)
do i = 1, npoin
dmat(i) = 0.0d00
enddo !i
do ie = 1, nelem
ar
= area(ie)*0.5d00
do i = 1,3
ip
= l(i,ie)
dmat(ip) = dmat(ip) + rho*cpp*ar/3.0
enddo!i
enddo !ie
do i = 1,npoin
dmat(i) = 1.0d00/dmat(i)
enddo !i
end
*********************************************************************
subroutine shape
*********************************************************************
*
* Calculation of derivatives of shape functions
*
implicit double precision(a-h, o-z)
parameter (np=5000,nel=10000,nbo=1000)
common/mesh1/npoin,nelem,nboud
common/mesh2/x(np),y(np),l(3,nel)
common/geom/geome(6,nel),area(nel)
dimension b1(nel),b2(nel),b3(nel),c1(nel),c2(nel),c3(nel)
dimension a1(nel),a2(nel),a3(nel)
do ie = 1,nelem
ip1
= l(1,ie)
ip2
= l(2,ie)
ip3
= l(3,ie)
b1(ie)
= y(ip2) - y(ip3)
b2(ie)
= y(ip3) - y(ip1)
b3(ie)
= y(ip1) - y(ip2)
c1(ie)
= x(ip3) - x(ip2)
c2(ie)
= x(ip1) - x(ip3)

c3(ie)
= x(ip2) - x(ip1)
a1(ie)
= x(ip2)*y(ip3) - x(ip3)*y(ip2)
a2(ie)
= x(ip3)*y(ip2) - x(ip1)*y(ip3)
a3(ie)
= x(ip1)*y(ip2) - x(ip2)*y(ip3)
area(ie)
= c3(ie)*b2(ie)-b3(ie)*c2(ie)
twoa
= 1.0d00/area(ie)
geome(1,ie) = twoa*b1(ie)
geome(2,ie) = twoa*b2(ie)
geome(3,ie) = twoa*b3(ie)
geome(4,ie) = twoa*c1(ie)
geome(5,ie) = twoa*c2(ie)
geome(6,ie) = twoa*c3(ie)
enddo !ie
end
******************************************************************
subroutine right1
******************************************************************
*
*
First term in the RHS
*
implicit double precision(a-h, o-z)
parameter (np=5000,nel=10000,nbo=1000)
common/mesh1/npoin,nelem,nboud
common/mesh2/x(np),y(np),l(3,nel)
common/pro1/rho,cpp,thr1,thr2
common/var/rhs(np),temp(np)
common/geom/geome(6,nel),area(nel)
do ip = 1,npoin
rhs(ip) = 0.0d00
enddo !ip
do ie = 1,nelem
const = rho*cpp*area(ie)/6.0
do i = 1,3
ip = l(i,ie)
rhs(ip) = rhs(ip) + const*temp(ip)
enddo !i
enddo !ip
end
******************************************************************
subroutine right2(tt1,tt2,qflx,ibc)
******************************************************************
*
* Calculation of second order temperature terms
*
implicit double precision(a-h, o-z)
parameter (np=5000,nel=10000,nbo=1000)
common/mesh1/npoin,nelem,nboud
common/mesh2/x(np),y(np),l(3,nel)
common/geom/geome(6,nel),area(nel)
common/pro1/rho,cpp,thr1,thr2
common/sol2/niter,idel,dtfix
common/var/rhs(np),temp(np)
common/mas/dmat(np)
common/bon1/isid(4,nbo)
common/erro/pretem(np)
common/bou2/alen(nbo),shin(nbo),chos(nbo)
common/htin/htco,tinf

dimension ibc(nbo)
do ie = 1,nelem
ip1 = l(1,ie)
ip2 = l(2,ie)
ip3 = l(3,ie)
const1 = dtfix*thr1*area(ie)/2.0
const2 = dtfix*thr2*area(ie)/2.0
dtdx = geome(1,ie)*temp(ip1)+geome(2,ie)*temp(ip2)+
&
geome(3,ie)*temp(ip3)
dtdy = geome(4,ie)*temp(ip1)+geome(5,ie)*temp(ip2)+
&
geome(6,ie)*temp(ip3)
rhs(ip1) = rhs(ip1) - const1*geome(1,ie)*dtdx &
const2*geome(4,ie)*dtdy
rhs(ip2) = rhs(ip2) - const1*geome(2,ie)*dtdx &
const2*geome(5,ie)*dtdy
rhs(ip3) = rhs(ip3) - const1*geome(3,ie)*dtdx &
const2*geome(6,ie)*dtdy
enddo !ie
do n = 1,nboud
is = isid(3,n)
is1 = isid(1,n)
is2 = isid(2,n)
*
*
*

convective heat transfer boundary condition

&
&
*
*
*

if(isid(4,n).eq.503)then
constc
= dtfix*htco*alen(n)*chos(n)/6.0
consts
= dtfix*htco*alen(n)*shin(n)/6.0
con1
= dtfix*htco*alen(n)*chos(n)/2.0
con2
= dtfix*htco*alen(n)*shin(n)/2.0
t1
= 2.0*temp(is1)+temp(is2)
t2
= temp(is1)+2.0*temp(is2)
rhs(is1) = rhs(is1)-constc*t1+con1*tinf
- consts*t1 + con2*tinf
rhs(is2) = rhs(is2)-constc*t2+con1*tinf
- consts*t2+con2*tinf
endif
heat flux boundary condition
if(isid(4,n).eq.504)then
con1
= qflx*dtfix*alen(n)*chos(n)/2.0
con2
= qflx*dtfix*alen(n)*shin(n)/2.0
rhs(is1) = rhs(is1)-con1-con2
rhs(is2) = rhs(is2)-con1-con2
endif
enddo !n
do i = 1,npoin
pretem(i) = temp(i)
temp(i)
= rhs(i)*dmat(i)
enddo !i

*
*
*

Applying constant temperature boundary conditions


do i = 1,nboud
if(isid(4,i).eq.501)then
is
= isid(1,i)

temp(is) = tt1
endif
if(isid(4,i).eq.502)then
is
= isid(1,i)
temp(is) = tt2
endif
enddo !i
end
******************************************************************
subroutine side
******************************************************************
*
* Calculation of boundary side length and direction cosines
*
implicit double precision(a-h, o-z)
parameter (np=5000,nel=10000,nbo=1000)
common/mesh1/npoin,nelem,nboud
common/mesh2/x(np),y(np),l(3,nel)
common/geom/geome(6,nel),area(nel)
common/pro1/rho,cp,thr1,thr2
common/bon1/isid(4,nbo)
common/bou2/alen(nbo),shin(nbo),chos(nbo)
do ib = 1,nboud
ip1
= isid(1,ib)
ip2
= isid(2,ib)
alen(ib) = dsqrt((x(ip1)-x(ip2))**2+(y(ip1)-y(ip2))**2)
shin(ib) = -(x(ip2)-x(ip1))/alen(ib)
chos(ib) = (y(ip2)-y(ip1))/alen(ib)
enddo !ib
end
******************************************************************
subroutine output
******************************************************************
*
*
Writing output
*
implicit double precision(a-h, o-z)
parameter (np=5000,nel=10000,nbo=1000)
common/mesh1/npoin,nelem,nboud
common/mesh2/x(np),y(np),l(3,nel)
common/var/rhs(np),temp(np)
common/bon1/isid(4,nbo)
rewind(12)
rewind(13)
write(12,*)0
write(12,*)'nelem,nodes etc'
write(12,*)nelem,npoin,nboud,1
write(12,*)'connectivity'
do i = 1,nelem
write(12,*)i,l(1,i),l(2,i),l(3,i)
enddo
write(12,*)'coordinates'
do ip = 1, npoin
write(12,*)ip,x(ip),y(ip)
enddo
write(12,*)'variables'
do ip = 1, npoin

write(12,6)ip,temp(ip),0.0,0.0,0.0
write(13,*)ip,temp(ip)
enddo !ip
write(12,*)'boundary'
do ie = 1,nboud
write(12,*)(isid(j,ie),j=1,4)
enddo
5
format (i5,4e16.6)
6
format (i5,4e16.6)
end
*****************************************************************
subroutine error
****************************************************************
*
* Steady state Convergence check
*
implicit double precision(a-h, o-z)
parameter (np=5000,nel=10000,nbo=1000)
common/mesh1/npoin,nelem,nboud
common/mesh2/x(np),y(np),l(3,nel)
common/var/rhs(np),temp(np)
common/erro/pretem(np)
dimension err(np)
ermax = 0.0
do i = 1,npoin
err(i) = dabs(pretem(i) - temp(i))
ermax
= max(ermax,err(i))
if(dabs(ermax-err(i)).le.0.000000001)then
node = i
endif
enddo
write(*,*)node,ermax
if(ermax.le.1d-10)then
write(*,*)'steady state reached'
stop
endif
end
****************************************************************

S-ar putea să vă placă și