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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
| import numpy as np
import matplotlib.pyplot as plt
import scipy.special as sp
import os #Pour atteindre les fichier , utile pour creer un fichier pour le GIF
import imageio #Creation du GIF
######################### Définition variables ###########################
V0=0.5 #m/s #vitesse vibratoire##
ro=1.225 #kg/m^3 ,masse volumique air à température 15°##
c=340 #m/s
w=340 #puls
f=w/(2*np.pi)
T=1/f #Periode
k=w/c
j=complex(0,1)
order=1
a=0.1 #rayon haut parleur en mètre##
lam=c/f
#Definitions F(r) et O(theta)
########################## FONCTIONS ######################################
def F(r):
return ((k*a**2)/2)*((np.exp(-j*k*r))/r)
def O(order,theta,w):
if theta.all()==np.radians(0) or theta.all()==np.radians(180): #O(theta)=1 pour theta 0,180 degré##
return 1
else:
return (2*sp.jv(order,k*a*np.sin(theta)))/(k*a*np.sin(theta)) #jv Fct bessel ordre 1 ici##
def CP(r,theta,t): #Champs de pression
return j*ro*c*V0*F(r)*O(1,theta,w)*np.exp(j*w*t)
t=0
rlist=np.linspace(30,40,1000)
thetalist=np.radians(np.linspace(0,361,1000))
rmesh, thetamesh = np.meshgrid(rlist,thetalist)
Fonction= CP(rmesh,thetamesh,t) #initiale, t=0
###################### Carto champ pression ##############################
fig, ax = plt.subplots(dpi=140,subplot_kw=dict(projection='polar'))
ax.set_thetamin(0)
ax.set_thetamax(360)
ax.set_xticks(np.arange(0,np.pi*2,np.pi/6.0))
#ax.set_rticks([0.5,1,1.5,2,4])
plt.contourf(thetamesh,rmesh,Fonction,10,cmap='gist_rainbow',extend='max')
plt.colorbar(pad=(0.08),aspect=(10))
############################ SAVE ########################################
fig, ax = plt.subplots(dpi=140,subplot_kw=dict(projection='polar'))
rlist=np.linspace(30,40,360)
thetalist=np.radians(np.linspace(0,361,360))
rmesh, thetamesh = np.meshgrid(rlist,thetalist)
ax.set_thetamin(0)
ax.set_thetamax(360)
ax.set_xticks(np.arange(0,np.pi*2,np.pi/6.0))
ax.set_rticks([20])
###################### Définition des dossier ############################
Dossier_Actuel = os.path.dirname(__file__) #dossier actuel
Dossiercréé = os.path.join(Dossier_Actuel, 'Animation/') #crée un chemin Dossieractuel/Animation
Noms_images = "Animation" #Nom des images qui seront sauvegardées.
if not os.path.isdir(Dossiercréé): #Si le dossier animation n'existe pas :
os.makedirs(Dossiercréé) #Le crée
image=[]
ticks=np.arange(-1,100,0.1)
for i in range (200): # temps pour 1000 itérations = environ 1heure !
t=i/10000 #c'est opti à fond
Fonction= CP(rmesh,thetamesh,t)
plt.contourf(thetamesh,rmesh,(Fonction),14,cmap='hot',extend='max')
if i == 0:
print("Création de l'animation,cela peut prendre un moment, merci de bien vouloir patienter :)...")
plt.colorbar(pad=(0.08),aspect=(10))
print(Fonction)
plt.title('Champs de pression dans le temps, t='+str(t)) #titre dynamique
plt.savefig(Dossiercréé + Noms_images +str(i),dpi=140) #enregistre images
################################ ANIM #####################################
Dossier_GIF = Dossiercréé
images = [] #crée une liste vide qui contiendra les images du gif
for file_name in os.listdir(Dossier_GIF): # crée liste des entrées des objets présent dans le repertoire
if file_name.endswith('.png'): #Tous les fichier .png (et seulement) du repertoire seront pris en compte dans la création du gif
file_path = os.path.join(Dossier_GIF, file_name) #crée un chemin Animation/Nom.gif
images.append(imageio.imread(file_path)) #ajoute toutes les images ensemble dans l'ordre prédéfini.
imageio.mimsave('{}/GIF.gif'.format(Dossier_GIF), images,fps=50) #sauvegarde le gif dans le dossier créé
print("Terminé ! Le GIF se trouve dans : " +Dossier_GIF)
"""
####################### Intensité rayonnée(carto) ###########################
def I(r,theta,k,w):
return ro*c*((V0**2)/2)*(((k**2)*(a**4))/(4*(r**2)))*(O(order,theta,w))**2
rlist=np.linspace(100,200,360)
thetalist=np.radians(np.linspace(0,361,360))
rmesh, thetamesh = np.meshgrid(rlist,thetalist)
FonctionI=I(rmesh,thetamesh,k,w)
fig, ax = plt.subplots(dpi=140,subplot_kw=dict(projection='polar'))
ax.set_thetamin(0)
ax.set_thetamax(360)
ax.set_xticks(np.arange(0,np.pi*2,np.pi/6.0))
#ax.set_rticks([100,500,100,500,1400])
plt.contourf(thetamesh,rmesh,(FonctionI),6,cmap='plasma',extend='max') #cmap='' pour changer style
plt.colorbar(pad=(0.08),aspect=(10))
########################## Directivité TEST ###############################
def F2(r):
return ((k*a**2)/2)*((np.exp(-j*k*r))/r)
def O2(order,theta,w,k):
if theta.all() == 0 or theta.all()==np.radians(2*np.pi) or theta.all()==(-2*np.pi):
return 1
else :
return (2*sp.jv(order,k*a*np.sin(theta)))/(k*a*np.sin(theta))##jv Fct bessel ordre 1 ici
def CP2(r,theta,t):###Champs de pression
return j*ro*c*V0*F(r)*O(1,theta,w)*np.exp(j*w*t)
def I2(r,theta,k,w):
return (ro*c*((V0**2)/2)*(((k**2)*(a**4))/(4*(r**2)))*(O2(order,theta,w,k)**2))
r=np.linspace(0.1,5,100)
theta=(np.linspace(0,2*np.pi,100))
order=1
k=1
w=3400
fig, ax = plt.subplots(dpi=140,subplot_kw=dict(projection='polar'))
for i inr range (1,11):
ax.plot((I2(r,theta,k*10*i,w*i)/I2(r,theta[0],10,w*i)))
ax.set_rticks([0.1,0.3,0.5,1,2])
""" |
Partager