import math
import numpy
from numpy import linalg
#Operating Conditions
ho = 1000; #[W/m^2.K] Heat Convection coefficient
hi = 200; #[W/m^2.K] Heat Convection coefficient
Ti = 400; #[K] Temp of Air
Tg = 1700; #[K] Temp of Gas
h = 10 ; #[W/m^2.K] Heat Convection coefficient
A = 2*6*math.pow(10,-6) ;#[m^2] Cross section of each Channel
x = .004 ; #[m] Spacing between joints
t = .006; #[m] Thickness
k = 25; #[W/m.K] Thermal Conductivity of Blade
delx = .001 ; #[m]
dely = .001 ; #[m]
#calculations and results
#Applying Eqn 4.42 and 4.48
A = numpy.array([[-(2+ho*delx/k), 1, 0,0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[1,-2*(2+ho*delx/k),1,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,1,-2*(2+ho*delx/k),1,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,1,-2*(2+ho*delx/k),1,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,1,-2*(2+ho*delx/k),1,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,1,-(2+ho*delx/k),0,0,0,0,0,1,0,0,0,0,0,0,0,0,0],
[1,0,0,0,0,0,-4,2,0,0,0,0,1,0,0,0,0,0,0,0,0],
[0,1,0,0,0,0,1,-4,1,0,0,0,0,1,0,0,0,0,0,0,0],
[0,0,1,0,0,0,0,1,-4,1,0,0,0,0,1,0,0,0,0,0,0],
[0,0,0,1,0,0,0,0,1,-4,1,0,0,0,0,1,0,0,0,0,0],
[0,0,0,0,1,0,0,0,0,1,-4,1,0,0,0,0,1,0,0,0,0],
[0,0,0,0,0,1,0,0,0,0,2,-4,0,0,0,0,0,1,0,0,0],
[0,0,0,0,0,0,1,0,0,0,0,0,-4,2,0,0,0,0,1,0,0],
[0,0,0,0,0,0,0,1,0,0,0,0,1,-4,1,0,0,0,0,1,0],
[0,0,0,0,0,0,0,0,2,0,0,0,0,2,-2*(3+hi*delx/k),1,0,0,0,0,1],
[0,0,0,0,0,0,0,0,0,2,0,0,0,0,1,-2*(2+hi*delx/k),1,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,1,-2*(2+hi*delx/k),1,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,-(2+hi*delx/k),0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,-2,1,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,1,-4,1],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,-(2+hi*delx/k)]]);
C = numpy.array([[-ho*delx*Tg/k],
[-2*ho*delx*Tg/k],
[-2*ho*delx*Tg/k],
[-2*ho*delx*Tg/k],
[-2*ho*delx*Tg/k],
[-ho*delx*Tg/k],
[0],
[0],
[0],
[0],
[0],
[0],
[0],
[0],
[-2*hi*delx*Ti/k],
[-2*hi*delx*Ti/k],
[-2*hi*delx*Ti/k],
[-hi*delx*Ti/k],
[0],
[0],
[-hi*delx*Ti/k]]);
T = numpy.linalg.solve (A,C);
print '%s' %("\n Temp Distribution in K = ");
print (T);
q = 4*ho*((delx/2.)*(Tg-T[0])+delx*(Tg-T[1])+delx*(Tg-T[2])+ delx*(Tg-T[3])+delx*(Tg-T[4])+delx*(Tg-T[5])/2.);
print '%s %.1f %s' %("\n\n Heat rate Transfer = " ,q,"W/m ");
#END