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
|
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#define Kx 6
#define Ky 8
#define N 48
#define K 1.0 //thermal conductivity,
#define TR 300.0 //
#define TL 300.0 //
#define TT 380.0 //Panel Face /Bottom Temerature
#define TB 300.0 //M-chasiss Face
#define aT 1.0 //relaxation factor (energy)
#define localre 0.001 //local residual for iterative method to solve matrix
#define localiter 50 //local iteration
using namespace std;
int main()
{
int i, j, js;
double S[N]; //source term
double l; //Localre
double K_Tstar[Ky][Kx];/// Previous stage temperature value
double T[Ky][Kx];//// Current stage temperature value
double Mk[N];// Arrangement for Matrix Breakdown
double Lex, Ley, dx, error, dy;//// Length direction variable
double aP, aE, aW, aS, aN;
double ke, kw, ks, kn;// Heat transfer coefficient
dx = 1.0 / Kx;
dy = 1.0 / Ky;
ke = dy / dx;
kw = dy / dx;
ks = dx / dy;
kn = dx / dy;
int Ms; //T initialize
for (i = 0; i < Ky; i++)
{
for (j = 0; j < Kx; j++)
{
T[i][j] = 300.0;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
for (Ms = 0; Ms < localiter; Ms++)
{
int x = 0;
int k = 0;//
//arrange u, v, source, p_prime to 1'col matrix
for (i = 0; i < Ky; i++)
{
for (j = 0; j < Kx; j++)
{
S[k] = 0.0;
l = 0.0;
Mk[k] = T[i][j];
K_Tstar[i][j] = T[i][j];
k++;
}
}
double **kP_T = NULL;// Memory Area Allocation
kP_T = new double *[N];
for (i = 0; i < N; i++)
{
kP_T[i] = new double[N];
}
for (i = 0; i < N; i++)
{
for (j = 0; j < N; j++)
{
kP_T[i][j] = 0.0;
}
}
//??? ??// Insert Initial Value
for (i = 0; i < N; i++)
{
for (j = 0; j < N; j++)
{
kP_T[i][j] = 0.0;
}
}
//T - matrix coefficient
k = 0;
for (i = 0; i < Ky; i++)
{
for (j = 0; j < Kx; j++)
{
if (i == 0)
{
if (j == 0) // bottom node, left column
{
kP_T[k][k + 1] = -ke;
kP_T[k][k - 1] = -kw;
kP_T[k][k - Ky] = -kn;
kP_T[k][k + Ky] = -ks;
kP_T[k][k] = -kP_T[k][k + 1] - kP_T[k][k + Ky] + 2.0*kn + 2.0*kw;
S[k] = 2.0 * kw*TL + 2.0 * kn*TT;
k++;
cout << kP_T[k][k] << endl;
}
}
}
}
}
return 0;
}
|