-- compile with gnatmake -gnataw main.adb -- Main driver to solve u_t + speed * u_x = 0 -- the advection PDE with periodic boundary -- conditions and with initial conditions sin(2*pi*x) -- -- Using Ada 2005 OO features -- For illustration and learning only. -- -- By Nasser M. Abbasi -- Match 26, 2011 with Ada.Text_IO; use Ada.Text_IO; with Lax_Wendroff_pkg; Use Lax_Wendroff_pkg; with Ada.Numerics; use Ada.Numerics; with Ada.Numerics.Generic_Elementary_Functions; procedure main is package Math is new Ada.Numerics.Generic_Elementary_Functions(Float); use Math; h : constant float := 0.01; -- grid space courant : constant float := 0.8; -- CFL condition speed : constant float := 1.0; -- flow speed k : constant float := courant*h/speed; -- time step size L : constant float := 1.0; -- domain length N : constant positive := natural(L/h)+1; --number of grid points -- generate initial condition function initialize(h: float; N: natural) return solution_t is data : solution_t(1..N) := (others=>0.0); x: float:=0.0; begin for i in data'range LOOP data(i) := sin(2.0*pi*x); x := x + h; end LOOP; RETURN(data); end; -- create the Lax-Wendroff object o : lax_Wendroff_t := make(speed=>speed , h=>h,k =>k, u0 =>initialize(h,N)); -- to print the final solution procedure print_solution(o: lax_wendroff_t) is u: constant solution_t := o.get_solution; begin FOR i in u'range LOOP put_line(float'image(u(i))); END LOOP; end; begin -- run for 100 steps for now FOR i in 1..100 LOOP o.step; print_solution(o); END LOOP; end main;