0% found this document useful (0 votes)
118 views

Matlab Code For Plate Diffusion Report

This document contains the code for a Fortran program that models heat transfer through a plate with boundary conditions. It initializes a heat matrix and error array. It then performs iterative calculations using relaxation to model the heat transfer through each node of the plate. It calculates the error at each node compared to the previous iteration. The maximum error is found and used as the termination criteria for the iterations. Upon completion it writes the number of iterations, total calculations, and final heat matrix values to the screen and a text file.

Uploaded by

Max Kondrath
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
118 views

Matlab Code For Plate Diffusion Report

This document contains the code for a Fortran program that models heat transfer through a plate with boundary conditions. It initializes a heat matrix and error array. It then performs iterative calculations using relaxation to model the heat transfer through each node of the plate. It calculates the error at each node compared to the previous iteration. The maximum error is found and used as the termination criteria for the iterations. Upon completion it writes the number of iterations, total calculations, and final heat matrix values to the screen and a text file.

Uploaded by

Max Kondrath
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

!

Max Kondrath
!HW #7
!3/20/12
program Plate7
real, dimension(16,11)::heat
real, dimension(500000) :: error
integer i, j, counter, dummy, dummer
real dx, relax, maxError
relax = 0.5
!0.5,1.0 or 1.5
oldval = 0
dx = 1
i = 1
j = 1
counter = 0
dummy = 1
dummer = 1
maxError = 100

!sets boundary conditions


!----------------------------------------------do i = 1,16
heat(i,1) = 50
end do
do dummy = 1, 500000
error(dummy) = 0
end do
!--------------------------------------------------do while (maxError>0.1)
j = 1
i = 1
dummy = 1
!left side insulated plate boundary condition
do j = 2,10
oldval = heat(1,j)
heat(1,j) = (2*heat(2,j) + heat(1,j+1)+heat(1,j-1))/4
heat(1,j) = (relax)*(heat(1,j)) + (1-relax)*oldval
error(dummy) = ((heat(1,j)-oldval)/heat(1,j))*100
dummy = dummy + 1
end do
!right side insulated boundary condition
do j = 2,5
oldval = heat(16,j)
heat(16,j) = (2* heat(15,j) + heat(16,j+1)+heat(16,j-1))/4
heat(16,j) = (relax)*(heat(16,j)) + (1-relax)*oldval
error(dummy) = ((heat(16,j)-oldval)/heat(16,j))*100
dummy = dummy + 1
end do

!bottom insulated boundary


do i = 2,10
oldval = heat(i,11)
heat(i,11) = (2* heat(i,10) + heat(i+1,11)+heat(i-1,11))/4
heat(i,11) = (relax)*(heat(i,11)) + (1-relax)*oldval
error(dummy) = ((heat(i,11)-oldval)/heat(i,11))*100
dummy = dummy + 1
end do

!loop for i and j to run through internal node for top sectional rectangle
do j = 2,6
do i = 2,15
oldval = heat(i,j)
heat(i,j) = (heat(i+1,j) + heat(i-1,j) + heat(i,j+1)+ heat(i,j-1))/4
heat(i,j) = (relax)*heat(i,j) + (1-relax)*oldval
error(dummy) = ((heat(i,j) - oldval)/heat(i,j))*100
dummy = dummy + 1
end do
end do
!loop for i and j to run through internal nodes for bottom sectional rectangle
do j = 7,10
do i = 2,11
oldval = heat(i,j)
heat(i,j) = (heat(i+1,j) + heat(i-1,j) + heat(i,j+1)+ heat(i,j-1))/4
heat(i,j) = (relax)*heat(i,j) + (1-relax)*oldval
error(dummy) = ((heat(i,j) - oldval)/heat(i,j))*100
dummy = dummy + 1
end do
end do
!customized iterations-------------------------------------------------------------------!extra nodes that have been avoided until this point in the iteration process ( for
simplicity )
dummy = dummy + 1
i = 12
j= 7
oldval = heat(i,j)
heat(i,j) = (heat(i+1,j) + heat(i-1,j) + heat(i,j+1)+ heat(i,j-1))/4
heat(i,j) = (relax)*heat(i,j) + (1-relax)*oldval
error(dummy) = ((heat(i,j) - oldval)/heat(i,j))*100
dummy = dummy + 1
i = 13
j=7
oldval = heat(i,j)
heat(i,j) = (heat(i+1,j) + heat(i-1,j) + heat(i,j+1)+ heat(i,j-1))/4
heat(i,j) = (relax)*heat(i,j) + (1-relax)*oldval
error(dummy) = ((heat(i,j) - oldval)/heat(i,j))*100
dummy = dummy + 1
i = 12
j=8
oldval = heat(i,j)
heat(i,j) = (heat(i+1,j) + heat(i-1,j) + heat(i,j+1)+ heat(i,j-1))/4
heat(i,j) = (relax)*heat(i,j) + (1-relax)*oldval

error(dummy) = ((heat(i,j) - oldval)/heat(i,j))*100


!END custom iterations--------------------------------------------------------------------!mini sections for curvilinear boundary----calculated by hand initially------dummy = dummy +1
oldval = heat(11,8)
heat(11,8) = ((.091735)*((heat(11,7)/2) + (heat(10,8)/.111201) + (heat(11,9)/2)))
heat(11,8) = (relax)*heat(11,8) + (1-relax)*oldval
error(dummy) = ((heat(i,j) - oldval)/heat(i,j))*100
dummy = dummy + 1
oldval = heat(11,7)
heat(11,7) = ((.294)*((heat(11,6)/2) + (heat(10,7)/.590889) + (heat(11,8)/2)))
heat(11,7) = (relax)*heat(11,7) + (1-relax)*oldval
error(dummy) = ((heat(i,j) - oldval)/heat(i,j))*100
dummy = dummy + 1
oldval = heat(12,6)
heat(12,6) = ((.294)*((heat(13,6)/2) + (heat(12,5)/.590889) + (heat(11,6)/2)))
heat(12,6) = (relax)*heat(12,6) + (1-relax)*oldval
error(dummy) = ((heat(i,j) - oldval)/heat(i,j))*100
dummy = dummy + 1
oldval = heat(13,6)
heat(13,6) = ((.091735) * ((heat(14,6)/2) + (heat(13,5)/.111201) + (heat(12,6)/2)))
heat(13,6) = (relax)*heat(13,6) + (1-relax)*oldval
error(dummy) = ((heat(i,j) - oldval)/heat(i,j))*100

counter = counter + 1
maxError = maxval(error)
write(*,*) "The max error for this iteration of calculations is", maxError
end do
!writes total iterations, dummy count (calculations per iteration I beleive),
heat/solution matrix
write(*,*) "Iterations#:", counter
write(*,*) "dummy count", dummy
write(*,"(16f8.2)") heat
!Creates text file to store heat matrix values
open( unit = 1, file = 'heat.txt')
write(1,"(16f8.2)") heat
close(unit=1)

end pro

You might also like