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
| from __future__ import division
import numpy as np
from matplotlib import pyplot as plt
N1=50 # nombre de point selon x et y
N=2*N1+1 # nombre de points total
# les grandeurs sont données en cm
xc1=4
xc2=9
yc1=0
yc2=0
R1=1.75
R2=9
a, b = np.linspace(-1, 19, N), np.linspace(-10, 10, N)
xa, ya = np.meshgrid(a, b)
V = np.zeros_like(xa)
for i in range(N):
for j in range(N):
x, y = xa[i,j], ya[i,j]
if est_ce_conducteur_central(x,y) :
V[i,j] = 30
#### Inutile, car V vaut deja 0 partout à l'état initial
# if est_ce_conducteur_exterieur(x,y) :
# V[i,j] =0
def est_ce_conducteur_exterieur(x,y):
return (((x-xc2)**2/(R2**2))+((y-yc2)**2/(R2**2)))>=1
def est_ce_conducteur_central(x,y):
return (((x-xc1)**2/(R1**2))+((y-yc1)**2/(R1**2)))<=1
def est_dans_domaine_de_calcul(x,y):
return not est_ce_conducteur_central(x,y) and not est_ce_conducteur_exterieur(x,y)
Vnew = V.copy()
ecart = 1
k=0
while ecart > 10**-4:
k+=1
for i in range(1,N-1):
for j in range(1,N-1):
if est_dans_domaine_de_calcul(xa[i,j],ya[i,j]):
# Vnew[i,j] = 1/24*(2*V[i-1,j] + 2*V[i+1,j] + 2*V[i,j-1] + 2*V[i,j+1] + 12*V[i,j]
# + V[i-1,j-1] + V[i-1,j+1] + V[i+1,j-1] + V[i+1, j+1] )
Vnew[i,j] = 0.25*(V[i-1,j] + V[i+1,j] + V [i,j-1] + V[i,j+1] )
ecart = np.max(np.abs(V - (Vnew))/np.max(V))
print(k,' ',ecart)
V=Vnew.copy()
fig=plt.figure()
ax=fig.add_subplot(1,1,1)
ax.plot(a,V[int(N/2),:])
plt.show() |
Partager