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
| import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as colors
from mpl_toolkits.mplot3d import Axes3D
# parametres de l'experience
L = 2.
tfin = 1
k = 1.
c = 1.
r = 1.
Tinit = 20
TextX0 = 50
TextL = 30
# pas de discretisation
hx = 0.2
ht = 0.05
Nx = int(L/hx)
Nt = int(tfin/ht)
x = np.linspace(0.0,2,Nx)
duree = np.linspace(0.0, tfin,Nt)
X,Y = np.meshgrid(x,duree) #pour definir un pavage du plan (produit cartsien)
#Contruction de la matrice A
alpha = (-k/(hx*hx))
beta = ((r*c)/ht)+((2*k)/(hx*hx))
gamma = (-k/(hx*hx))
A = np.zeros([Nt+1,Nt+1],'d')
for i in xrange (0,Nt,1):
A[i,i] = beta
A[i,i+1] = gamma
A[i+1,i] = alpha
A[Nt,Nt] = beta
A[Nt,Nt-1] = alpha
Ainv = np.linalg.inv(A)
#Construction de la matrice T
b0 = np.zeros([1,Nt+1],'d')
for i in xrange(0,Nt,1):
b0[0][i] = 20
#b0 = [20 for k in xrange(0,Nt+1)]
B0 = b0.transpose()
t0 = np.zeros([1,Nt+1],'d')
t0[0] = 50
T0 = t0.transpose()
T = np.zeros([Nt+1,Nt+1],'d')
# Conditions initiales
for i in range(0,Nx):
T[0][i] = 20
# Conditions aux limites
for t in range(1,Nt+1):
T[t][0] = 50
T[t][-1] = 30
P = B0
for t in range(0,Nt):
TT = np.dot(Ainv,P)+ np.dot(Ainv,T0)
TT1 = TT.transpose()
for i in xrange(0,Nt,1):
T[t+1][i] = TT1[0][i]
P = TT
# affichage de l'evolution de la temperature
fig = plt.figure(figsize=(14,8)) #taille de la figure
ax = fig.add_subplot(111, projection='3d')
ax.set_xlabel('X', fontsize = 16) #legendes
ax.set_ylabel('temps', fontsize = 16) #des differents
ax.set_zlabel('temperature', fontsize = 16) #axes
ax.view_init(elev=15, azim = 120)
norm = colors.Normalize(Tinit,TextX0,TextL)
p = ax.plot_surface(X,Y,T,cstride=1,linewidth=0,cmap='jet')
cb = fig.colorbar(p,ax = ax)
plt.show() |
Partager