You are on page 1of 3

Janmejay Jaiswal

IIST

Numerical solutions of the classical Blasius flat-plate


problem
Method used for solving PDE is Runge Kutta
C Program (Blasius.cpp)
#include <stdio.h>
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
//Increment in eta
double h=.01 ;
//Boundary condition
long double fd0=0 ,f0=0 ;
//Initial Guess
long double s0=.1 ;
long double fd;
long double u0=0 ;
long double k1,l1,m1,k2,l2,m2,l3,k3,m3,k4,l4,m4;
long double ui,vi,fi;
long double e=.0001 ,phi1,phi2;
long double s=s0;
while (1 )
{
ui=u0;
vi=s;
fi=f0;
for (int n=0 ;n<1001 ;n++)
{
k1=h*ui;
l1=h*vi;
m1=(-h)*(vi*fi)/2 ;
k2=h*(ui+.5 *l1);
l2=h*(vi+.5 *m1);
m2=(-h)*(vi+.5 *m1)*(fi+.5 *k1)/2 ;
k3=h*(ui+.5 *l2);
l3=h*(vi+.5 *m2);
m3=(-h)*(vi+.5 *m2)*(fi+.5 *k2)/2 ;
k4=h*(ui+l3);
l4=h*(vi+m3);
m4=(-h)*(vi+m3)*(fi+k3)/2 ;
fi=fi+(k1+2 *k2+2 *k3+k4)/6 ;
ui=ui+(l1+2 *l2+2 *l3+l4)/6 ;
vi=vi+(m1+2 *m2+2 *m3+m4)/6 ;
}
phi1=abs(ui-1 );
vi=s+e;
ui=u0;
fi=f0;
for (int n=0 ;n<1001 ;n++)
{
k1=h*ui;
l1=h*vi;
m1=(-h)*(vi*fi)/2 ;
k2=h*(ui+.5 *l1);

l2=h*(vi+.5 *m1);
m2=(-h)*(vi+.5 *m1)*(fi+.5 *k1)/2 ;
k3=h*(ui+.5 *l2);
l3=h*(vi+.5 *m2);
m3=(-h)*(vi+.5 *m2)*(fi+.5 *k2)/2 ;
k4=h*(ui+l3);
l4=h*(vi+m3);
m4=(-h)*(vi+m3)*(fi+k3)/2 ;
fi=fi+(k1+2 *k2+2 *k3+k4)/6 ;
ui=ui+(l1+2 *l2+2 *l3+l4)/6 ;
vi=vi+(m1+2 *m2+2 *m3+m4)/6 ;
Blasius.cpp Sunday 22 May 2011 10:48:02 IST
Page 2 of 2
}
phi2=abs(ui-1 );
long double slope=(phi2-phi1)/e;
long double s1=s;
s=s-(phi1/slope);
//defining tolerance
long double tol=abs(s1-s);
if (tol<.0001 )
break ;
}
//After convergence we will get true value of s for which we will calculate solution
vi=s;
ui=u0;
fi=f0;
cout<<"0" <<" " <<fi<<" " <<ui<<" " <<vi<<endl;
for (int n=0 ;n<1001 ;n++)
{
k1=h*ui;
l1=h*vi;
m1=(-h)*(vi*fi)/2 ;
k2=h*(ui+.5 *l1);
l2=h*(vi+.5 *m1);
m2=(-h)*(vi+.5 *m1)*(fi+.5 *k1)/2 ;
k3=h*(ui+.5 *l2);
l3=h*(vi+.5 *m2);
m3=(-h)*(vi+.5 *m2)*(fi+.5 *k2)/2 ;
k4=h*(ui+l3);
l4=h*(vi+m3);
m4=(-h)*(vi+m3)*(fi+k3)/2 ;
fi=fi+(k1+2 *k2+2 *k3+k4)/6 ;
ui=ui+(l1+2 *l2+2 *l3+l4)/6 ;
vi=vi+(m1+2 *m2+2 *m3+m4)/6 ;
cout<<(n+1 )*h<<" " <<fi<<" " <<ui<<" " <<vi<<endl;
}
return 0 ;
}

Gnuplot file (Blasius.gnu)


set terminal postscript eps size 3.5,2.62 enhanced color font 'Helvetica,20' lw 2

set output 'Blasius.eps'


#set border linewidth 1.5
#set style line 1 linecolor rgb '#0060ad' linetype 1 linewidth 2 # blue
#set style line 2 linecolor rgb '#dd181f' linetype 1 linewidth 2 # red
set key at 10,1.6
set xrange [0:10]
set yrange [0:1.6]
set grid
set pointsize .1

set xlabel "{/Symbol h}"


plot "Blasius.dat" using 1:2 title "f({/Symbol h})", "Blasius.dat" using 1:3 title "f'({/Symbol h})", "Blasius.dat"
using 1:4 title "f''({/Symbol h})"

To run above program


1.
2.
3.
4.
5.

Go to terminal
Go to the directory of file
Type command g++ -o Blasius Blasius.cpp and enter
Type command ./Blasius ->Blasius.dat and enter this will generate datafile i.e solution of pde
Type command gnuplot < Blasius.gnu and enter this will generate Blasius.eps file in which graph is
ploted.

You might also like