Solving the advection PDE in 1-D using Ada 2005 Object oriented features

by Nasser M. Abbasi



Contents

introduction

This PDF file contains this page in PDF format. To help me learn a little more about Ada, I wrote 1 the following small program to solve the advection pde $ u_t + a u_x=0$ with initial condition $ u(x,0)=sin(2\pi x)$ and with periodic boundary conditions $ u(0,t)=u(1,t)$.

To be able to plot the solution, I directed the output of the program to a text file, then loaded the text file to Matlab and ran the simulation that way.

The program contains 3 files

  1. main.adb the main line.
  2. lax_wendroff_pkg.ads the package interface.
  3. lax_wendroff_pkg.adb the package body.

To compile, I did

$ gnatmake -gnat05  -gnatwa main.adb
gcc -c -gnat05 -gnatwa lax_wendroff_pkg.adb
gnatbind -x main.ali
gnatlink main.ali

To run, I did

./main > result.txt

To see the simulation, then from Matlab, I run the following script

A=load('result.txt','-ascii');
B=reshape(A,100,100);

for i=1:size(B,2)
    plot(B(:,i))
    ylim([-1 1]);    
    drawnow();
   
    pause(0.01);
end



Footnotes

... wrote1
thanks goes to Randy Brukardt, Pascal Obry, Shark8 and others for giving helpful advice on Ada coding at comp.lang.ada


me 2011-03-28