Verifying Fortran MacCormack Algorithm at t=50*dt

  • Fortran
  • Thread starter Cassius1n
  • Start date
  • Tags
    Fortran
In summary, the conversation is about a problem solving the Maccormack algorithm for a given equation, and the person is asking for advice on how to fix an error they are encountering in their code.
  • #1
Cassius1n
13
0
Hi i have a problem in solving the maccormack algorithm for the following :
∂p/∂t+8*∂p/∂x=0,x∈(-10,10)
p(x,t=0)=e**-3x
the exact solution is u exact(x,t)=e**-3(x-8t)
I have to verify the solution with the exact solution at t=50* dt
This is what I've done so far:

Fortran:
implicit none
    integer,parameter::Nx=100
    real*8,parameter::a1=-10.d0,b1=10.d0,CFL=0.01d0,a=8.d0
    real*8,dimension(0:Nx)::uM,uaux,unew,x
    real*8::u_ex,f1,g1,g2,f,eror,t,t1,dx,dt,tfinal
    integer::i,contor
  
  
   
    open(1,file='MacCormack_rez.txt')
   
  
   
    dx=(b1-a1)/Nx
    dt=CFL*dx/a
    t=0.d0
    contor=0
    tfinal=50.d0*dt
  
    t=0 (
    do i=0,Nx
        x(i)=a1+i*dx
    
       
        uM(i)=f1(x(i))
       
    end do
    write (1,100) (f1(x(i)),i=0,Nx)
 
  
  
    do while(t<tfinal)
        t=t+dt               
        t1=t-dt/2.d0
       
       
        
       2.Mac Cormack
      
         do i=1,Nx-1           
             uaux(i)=uM(i)-CFL*(uM(i+1)-uM(i))
        end do
      
      
        do i=1,Nx-1
             unew(i)=1/2.d0*((uM(i)+uaux(i))-CFL*(uaux(i)-uaux(i-1)))   
        end do
        unew(0)=g1(t)
        unew(Nx)=g2(t)
        uM=unew
         write(2,100)(uM(i),i=0,Nx)
    
   t=50.d0*dt
  
    write (1,100) (u_ex(x(i),t,a),i=0,Nx)

    write(*,*) 'End program'
    read(*,*)
100 format(120(f16.9,1x))
  

    end program
  
    function u_ex(x,t,a)
    implicit none
    real*8::u_ex,x,t,a
    real*8,parameter:: pi=4.d0*datan(1.d0)
    u_ex=dexp(-3.d0*(x-a*t))
    end function
  
  
    function f1(x)
    implicit none
    real*8::f1,x
    real*8,parameter:: pi=4.d0*datan(1.d0)
    f1=dexp(-3.d0*x)
    end function
  
  
    function g1(t)
    implicit none
    real*8::g1,t
    real*8,parameter:: pi=4.d0*datan(1.d0)
    g1=0.d0
    end function
  
    function g2(t)
    implicit none
    real*8::g2,t
    real*8,parameter:: pi=4.d0*datan(1.d0)
    g2=0.d0
    end function
  
  
        function f(x,t)                             
    implicit none
    real*8::f,x,t
    real*8,parameter:: pi=4.d0*datan(1.d0)
    f=0.d0
    end function

Can someone give me an advice ,please?
 
Technology news on Phys.org
  • #2
Welcome to PF!

So what's wrong? A compiler error? A runtime error?
 
  • #3
jedishrfu said:
Welcome to PF!

So what's wrong? A compiler error? A runtime error?
upload_2017-1-20_7-29-9.png
 
  • #4
Cassius1n said:
Hi i have a problem in solving the maccormack algorithm for the following :
∂p/∂t+8*∂p/∂x=0,x∈(-10,10)
p(x,t=0)=e**-3x
the exact solution is u exact(x,t)=e**-3(x-8t)
I have to verify the solution with the exact solution at t=50* dt
This is what I've done so far:

Fortran:
implicit none
    integer,parameter::Nx=100
    real*8,parameter::a1=-10.d0,b1=10.d0,CFL=0.01d0,a=8.d0
    real*8,dimension(0:Nx)::uM,uaux,unew,x
    real*8::u_ex,f1,g1,g2,f,eror,t,t1,dx,dt,tfinal
    integer::i,contor
 
 
  
    open(1,file='MacCormack_rez.txt')
  
 
  
    dx=(b1-a1)/Nx
    dt=CFL*dx/a
    t=0.d0
    contor=0
    tfinal=50.d0*dt
 
    t=0 (
    do i=0,Nx
        x(i)=a1+i*dx
   
      
        uM(i)=f1(x(i))
      
    end do
    write (1,100) (f1(x(i)),i=0,Nx)
 
 
 
    do while(t<tfinal)
        t=t+dt              
        t1=t-dt/2.d0
      
      
       
       2.Mac Cormack
     
         do i=1,Nx-1          
             uaux(i)=uM(i)-CFL*(uM(i+1)-uM(i))
        end do
     
     
        do i=1,Nx-1
             unew(i)=1/2.d0*((uM(i)+uaux(i))-CFL*(uaux(i)-uaux(i-1)))  
        end do
        unew(0)=g1(t)
        unew(Nx)=g2(t)
        uM=unew
         write(2,100)(uM(i),i=0,Nx)
   
   t=50.d0*dt
 
    write (1,100) (u_ex(x(i),t,a),i=0,Nx)

    write(*,*) 'End program'
    read(*,*)
100 format(120(f16.9,1x))
 

    end program
 
    function u_ex(x,t,a)
    implicit none
    real*8::u_ex,x,t,a
    real*8,parameter:: pi=4.d0*datan(1.d0)
    u_ex=dexp(-3.d0*(x-a*t))
    end function
 
 
    function f1(x)
    implicit none
    real*8::f1,x
    real*8,parameter:: pi=4.d0*datan(1.d0)
    f1=dexp(-3.d0*x)
    end function
 
 
    function g1(t)
    implicit none
    real*8::g1,t
    real*8,parameter:: pi=4.d0*datan(1.d0)
    g1=0.d0
    end function
 
    function g2(t)
    implicit none
    real*8::g2,t
    real*8,parameter:: pi=4.d0*datan(1.d0)
    g2=0.d0
    end function
 
 
        function f(x,t)                            
    implicit none
    real*8::f,x,t
    real*8,parameter:: pi=4.d0*datan(1.d0)
    f=0.d0
    end function

Can someone give me an advice ,please?
Your error, which was just barely legible in you screen shot, is "An unterminated block exists".

You're missing a program statement at the beginning of your main program. You have an end program statement, but not the program statement.

It should look something like this
Fortran:
program maccormack
    
    implicit none
    integer,parameter::Nx=100
    real*8,parameter::a1=-10.d0,b1=10.d0,CFL=0.01d0,a=8.d0
    real*8,dimension(0:Nx)::uM,uaux,unew,x
    real*8::u_ex,f1,g1,g2,f,eror,t,t1,dx,dt,tfinal
    integer::i,contor
    ! etc.
end program

function u_ex(x,t,a)
    implicit none
    real*8::u_ex,x,t,a
    real*8,parameter:: pi=4.d0*datan(1.d0)
    u_ex=dexp(-3.d0*(x-a*t))
end function

! Other function definitions
Also, this line:
Code:
      2.Mac Cormack
should either be removed or made into a comment. It is invalid Fortran code.
 
  • #5
Thank you for your response!
 

FAQ: Verifying Fortran MacCormack Algorithm at t=50*dt

1. What is the purpose of verifying the Fortran MacCormack Algorithm at t=50*dt?

The purpose of verifying the Fortran MacCormack Algorithm at t=50*dt is to ensure the accuracy and reliability of the algorithm in solving a specific problem. By testing the algorithm at a specific time step, we can determine if it is producing correct results and identify any potential errors or issues that may need to be addressed.

2. How is the Fortran MacCormack Algorithm verified at t=50*dt?

The Fortran MacCormack Algorithm can be verified at t=50*dt by comparing the results it produces to known analytical solutions or experimental data. If the results match, it can be considered verified. Other methods such as code reviews and unit testing can also be used to verify the algorithm.

3. Why is it important to verify the Fortran MacCormack Algorithm at t=50*dt?

Verifying the Fortran MacCormack Algorithm at t=50*dt is important because it ensures the accuracy and reliability of the algorithm in solving a specific problem. This is crucial in scientific research and engineering, as incorrect results can lead to incorrect conclusions and potentially disastrous consequences.

4. What are some challenges that may arise when verifying the Fortran MacCormack Algorithm at t=50*dt?

Some challenges that may arise when verifying the Fortran MacCormack Algorithm at t=50*dt include identifying errors or bugs in the code, ensuring the correct implementation of the algorithm, and dealing with complex or nonlinear problems that may not have analytical solutions for comparison.

5. Can the Fortran MacCormack Algorithm be verified at a different time step?

Yes, the Fortran MacCormack Algorithm can be verified at a different time step, such as t=20*dt or t=100*dt. However, t=50*dt is a commonly used time step for verification as it is a midway point that can provide a good indication of the algorithm's accuracy throughout the simulation.

Similar threads

Replies
4
Views
1K
Replies
4
Views
1K
Replies
8
Views
1K
Replies
3
Views
1K
Replies
20
Views
2K
Replies
54
Views
4K
Replies
6
Views
1K
Back
Top