Solving heat equation using crank-nicolsan scheme in FORTRAN

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Solving heat equation using crank-nicolsan scheme in FORTRAN
# 1  
Old 02-03-2014
Solving heat equation using crank-nicolsan scheme in FORTRAN

Code:
! The one-dimensional PDE for heat diffusion equation
! u_t=(D(u)u_x)_x + s where u(x,t) is the temperature,
! D(u) is the diffusivity and s(x,t) is a source term.
! Taking D(u)= 1 and s(x,t)=0 gives
! u_t= u_xx
! uniform one dimensional region |x|<1 for t>0
! uniform mesh size delta x=0.1
! Initial condition : u(x)= (1+x)(1-x)^2
 
Program crank_nicolson
Implicit none
Real, allocatable :: x(:),u(:,:),a(:),b(:),c(:),d(:)
Real:: m,dx,dt,Tmax
Integer:: n,j,NI,JI
Print*, 'Enter the total number of time steps'
read*, NI
Print*, 'Enter the final time'
read*, Tmax
dt=Tmax/NI !The size of timestep
Print*, 'This gives stepsize of time dt=',dt 
dx= 0.1 !delta x =0.1
allocate (x(0:JI),u(0:NI,0:JI),a(0:JI),b(0:JI),c(0:JI),d(0:JI))
m = dt/(2*dx**2)
JI= 20
open(10,file='crank_nicolsan.m')
!Initial Condition
do j=1,JI-1
x(j)= -1+j*dx
u(0,j)=(1+x(j))*(1-x(j))**2 !x=-1+j*dx
end do
x(0)= -1
x(JI)= 1
!Boundary condition
do n=0,NI
u(n,0)=0 !b.c. at j=0
u(n,JI)=0 !b.c. at j=JI
end do
do n =0 , NI !loop
do j = 1, JI ! a,b,c,d are the coefficients of C-N scheme 
a(j) = -m
b(j) = 1+2*m
c(j) = -m
d(j) = m*u(n,j+1)+(1-2*m)*u(n,j)+m*u(n,j-1) 
end do
end do
 
do j=1, JI-1
do n=1, NI-1
u(n,j)=d(j)
end do
end do
call thomas(a,b,c,d,JI)
!Print out the Approximate solution in matlab file
write(10,*) 'ApproximateSolution =[',x(0),u(0,0)
do j =1, JI
write(10,*) x(j),u(n,j)
end do
write(10,*)x(JI),u(NI,JI),']'
 
end Program crank_nicolson
 
subroutine thomas (a,b,c,d,JI)
implicit none
real, intent(inout) :: a(*),b(*),c(*),d(*)
integer, intent(in) :: JI 
integer j
 
do j = 2,JI !combined decomposition and forward substitution
a(j) = a(j)/b(j-1)
b(j) = b(j)-a(j)*c(j-1)
d(j) = d(j)-a(j)*d(j-1)
end do 
 
!back substitution
d(j) = d(j)/b(j)
do j = JI-1,1,-1
d(j) = (d(j)-c(j)*d(j+1))/b(j)
end do
return
end subroutine thomas


I got run time error - undefined variables, arrays or element of function in this line :
Code:
allocate (x(0:NI),u(0:JI),a(0:JI),b(0:JI),c(0:JI),d(0:JI))

There might be some other errors and code missing too. Can anyone help me please.
Thanks in advance

Moderator's Comments:
Mod Comment Please indent your code,
so it becomes easier to read

Last edited by Scrutinizer; 02-04-2014 at 12:41 AM.. Reason: Wrong kind of code tags (icode instead of code)
This User Gave Thanks to watto1 For This Post:
# 2  
Old 04-02-2014
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

E**(i*pi)=-1 or e**(j*pi)=-1, something I found out in Python using part of Eulers Identit equation.

Well guys and gals I have discovered after all these years that Python does complex numbers without the 'complex()' function or 'cmath' import. It is well known that Euler's Identity E**(i*pi)+1=0 so I decided to experiment Last login: Fri Dec 13 18:27:30 on ttys000 AMIGA:amiga~> python3.8... (0 Replies)
Discussion started by: wisecracker
0 Replies

2. Shell Programming and Scripting

Help with insert a value equation in bash script

HI All, I have a script in bash that i want that script will perform action When the size of a particular folder exceeds the 80%. Here is an example of script that result is exactly 80% : #!/bin/bash CHECK=$(df -h /var/log/syslog | grep '80%' | xargs echo | cut -d' ' -f5) if ];... (1 Reply)
Discussion started by: Aviel.shani
1 Replies

3. Solaris

SunFire V240 CPU Heat Sink Replacement

I got a replacement Heatsink and Fan unit, but the OEM unit has the SUN Thermal Interface Material (TIM) already on the heatsink matting surface. Because mine is used it does not have the TIM. Also there are 2 different TIM material SUN used based on the Processor (1-1.28GHz uses a glue backed... (1 Reply)
Discussion started by: danneskjold0809
1 Replies

4. Solaris

Sun Fire v440 Over heat Problem.

Dear Team, I need some expert advice to my problem. We have a Sun Fire v440 in our customer Place. Server is working fine and no hardware deviations are found except one problem that processors generating too much heat. I have verified and found that the room temperature was 26-27 degree.... (5 Replies)
Discussion started by: sudhansu
5 Replies

5. High Performance Computing

Performance Equation

I'm running a MPI program using a cluster of 4 machines(different machines of different processing power,cpu utilization etc.). I'm trying to balance the computation among the machine to get the minimum execution time for that. I tried to balance it by creating a threshold value by taking the load... (1 Reply)
Discussion started by: chamila1986
1 Replies

6. Shell Programming and Scripting

Perl - maths equation - need help

if input to the perl program is ' ( p * ((a+b) * (c+d))) + q ' it shuld give the output as ' pac + pad + pbc + pbd + q ' .can anyone suggest a way to do this ? (7 Replies)
Discussion started by: Anuj8584
7 Replies

7. Shell Programming and Scripting

AWK equation evaluation.

Hi, Is there a way to evaluate an equation contained in a string within an AWK script? For example: A = "(5*2)-1" (this equation is read from a file and varies line by line) In this example, I can't see any way to get an answer of 9 unless I do: cmd = "awk 'BEGIN{print "A"}'" cmd |... (3 Replies)
Discussion started by: srdgeo
3 Replies

8. AIX

Heat monitor for AIX

Hi. Does anyone know if there is a command in AIX to find out your machine heat? Perhaps something to cat out of proc? (1 Reply)
Discussion started by: Sprellarinn
1 Replies

9. UNIX for Dummies Questions & Answers

equation calculation on Unix

Hay, guys, Any ideas how to calculate like this: in first file, there're number of lines listing 2+3, 6*9 ....... Then, how to get the result and put them in another file in format: 2+3 5 6*9 54 ...... sheerly by shell command, no scripts required. (4 Replies)
Discussion started by: robbinGlasses
4 Replies
Login or Register to Ask a Question