1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
#include <iostream.h>
#include <conio.h>
#include <algorithm>
void print();
class explict
{
private:
float a,b,c,d,e,f,u[100];
float un[100];
public:
int read_data (float &a,float &b, float &c, float &d, float &e, float &f)
{
print();
cout<<"\nThis program computes the velcoity of suddenly accelerated plate \nover a period of time \n";
print();
cout<<"\nPlease Enter the following details in SI units.....\n\n";
cout<<"Distance between the two plates (h) m :";cin>>a;
cout<<"Velocity of the moving plate (u0) m/s :";cin>>b;
cout<<"Kinematic viscosity of fluid (v) m2/s:";cin>>c;
print();
cout<<"\nSetting the Grid for the problem...\n\nGrid Spacing required along\n1.Y-Direction\t\t:";cin>>d;
cout<<"2.Time step Interval\t:";cin>>e;
cout<<"Time step at which velcoity to be found:";cin>>f;
print();cout<<"\n";
}
int array (float *uu, int m,float c)
{
for(int i=0;i<=m-1;i++)
{
if(i==m-1)
{uu[i]=c;}else
{uu[i]=0;}
//cout<<i<<"\t"<<u[i]<<"\n";
}
}
int ftcs (float aa,float bb,float a,float d,float* u,int m,float o)
{
for (int k=1;k<=aa/bb+1;k++)
{
cout<<"\nTime Step:"<<k<<" Sec\n";
std::copy (u,u+m,un);
for (int j=1;j<a/d;j++)
{
u[j]=un[j]+o*(un[j+1]-(2*un[j])+un[j-1]);
cout<<"\n"<<j<<"\t"<<u[j];
}cout<<"\n";
}
}
};
int main()
{
float h,u0,v,dx,dt,t,d,uu[100];
int n,cc;
explict x;
x.read_data(h,u0,v,dx,dt,t);
d=v*(dt/(dx*dx));
n=(h/dx)+1;
cout<<h<<"\t"<<dx<<"\t"<<n<<"\t"<<d<<"\n";
x.array ( &uu[100] ,n+1,u0 );
cout<<"Initialization Completed"<<"\n\n";
float* u=&uu[100];
cout<<"Starting Calculation"<<"\n";
x.ftcs (t,dt,h,dx,&u[100],n+1,d);
getch();
}
void print()
{
cout<<"-----------------------------------------------------------------";
}
|