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
|
#include <iostream>
#include <vector>
using namespace std;
typedef vector<double> VD;
typedef vector<VD> VVD;
void grid (
int nx, int ny,
double lx, double ly,
double &dx, double &dy,
VVD &x, VVD &y)
{
dx = lx / nx;
dy = ly / ny;
for (int i = 0; i < nx+1; i++){
for (int j = 0; j < ny+1; j++){
x[i][j] = (i - 1) * dx;
y[i][j] = (j - 1) * dy;
}
}
}
void input(
int &nx, int &ny,
double &lx, double &ly,
double &k, double &ro, double &cp, double &alfa,
double &Tl, double &Tr, double &Ts, double &Tn,
double &q, int &ml, int &mr, int &ms, int &mn)
{
double AR = 1; // aspect ratio
lx = 1; // length
ly = AR * lx; // height
nx = 20; // x-division number
ny = 20; // y-division number
k = 1; // conductivity
ro = 1; // density
cp = 1; // heat capacity
alfa = k / (ro * cp); // thermal difusivity
q = 0; // heat flux/(ro*cp)
// boundary indicator (Dirichlet: m=0 and Neumann: m=1) when m=0
//left bondary
ml = 0; Tl = (ml == 0);
// right boundary
mr = 0; Tr = (mr == 0);
// south boundary
ms = 1; Ts = (ms != 0);
// north boundary
mn = 0; Tn = (mn != 0);
}
int main()
{
int nx, ny, ml, mr, ms, mn;
double k, lx, ly, dx, dy, ro, cp, alfa, q, Tl, Tr, Ts, Tn;
input(nx, ny, lx, ly, k, ro, cp, alfa, Tl, Tr, Ts, Tn, q, ml, mr, ms, mn);
VVD x (nx+1, VD(ny+1)),
y (nx+1, VD(ny+1)),
T (nx+1, VD(ny+1)),
aw(nx+1, VD(ny+1)),
as(nx+1, VD(ny+1)),
ap(nx+1, VD(ny+1)),
ae(nx+1, VD(ny+1)),
an(nx+1, VD(ny+1)),
bp(nx+1, VD(ny+1));
grid (nx, ny, lx, ly, dx, dy, x, y);
cout << x[1][5] << endl;
return 0;
}
|