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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
#include <iostream.h>
#include <conio.h>
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <string>
#include <direct.h>
using namespace std;
void print();
void complete();
class explict
{
private:
float un[100],h[100],g[100];
static const string result;
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\t (m):";cin>>d;
cout<<"2.Time step Interval\t\t\t(m):";cin>>e;
cout<<"\nTime step at which velcoity to be found (s):";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 initialize (int m, float o,float* aa,float* bb,float* cc,float* dd, float* u)
{
for (int i=1;i<m;i++)
{
aa[i]=o;
bb[i]=-(2*o+1);
cc[i]=o;
switch (i)
{
case 1:
dd[i]=-1-(aa[i]*u[i-1]);break;
case 39:
dd[i]=-1-(aa[i]*u[i+1]);break;
default:
dd[i]=-1;break;
}
//cout<<i<<"\t"<<aa[i]<<"\t"<<bb[i]<<"\t"<<cc[i]<<"\t"<<dd[i]<<"\n";
}
}
int tdms (int m, float* x,float* y,float* z, float* w, float* u,float tt,float ddt )
{
for(int k=1; k<=tt/ddt+1;k++)
{
std::copy(u,u+m,un);
h[0]=0;g[0]=0;
for(int i=1;i<m;i++)
{
h[i]=z[i]/(y[i]-(x[i]*h[i-1]));
g[i]=(w[i]-(x[i]*g[i-1]))/(y[i]-(x[i]*h[i-1]));
}
un[m-1]=g[m-1];cout<<m-1<<"\t"<<un[m-1]<<"\n";
for(int i=(m-2);i>0;i--)
{
u[i] =(-h[i]*un[i+1])+g[i];
cout<<i<<"\t"<<u[i]<<"\n";
}//cout<<1<<"\t"<<h[1]<<"\t"<<g[1]<<"\t"<<z[1]<<"\t"<<y[1]<<"\t"<<x[1]<<"\t"<<u[m-2]<<"\t"<<u[m-1]<<"\n";
}
}
};
int main()
{
float h,u0,v,dx,dt,t,d,uu[100],aa[100],bb[100],cc[100],dd[100];
int n,a;
explict x;
x.read_data(h,u0,v,dx,dt,t);
d=v*(dt/(dx*dx));
n=(h/dx); //cout<<h<<"\t"<<dx<<"\t"<<n<<"\t"<<d<<"\n";
x.array ( uu ,n+1,u0 );
x.initialize(n,d,aa,bb,cc,dd,uu);
x.tdms(n,aa,bb,cc,dd,uu,t,dt);cout<<"\n";
getch();
}
void print()
{
cout<<"-----------------------------------------------------------------";
}
void complete()
{
cout<<"\nSolution is Obtained\n";
print();
}
| |