Skip to content

Instantly share code, notes, and snippets.

@nim65s
Created April 14, 2019 18:52
Show Gist options
  • Save nim65s/41fd46beec1a17e6d7be91ee3d0c9e0f to your computer and use it in GitHub Desktop.
Save nim65s/41fd46beec1a17e6d7be91ee3d0c9e0f to your computer and use it in GitHub Desktop.
Effet de peau
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Populating the interactive namespace from numpy and matplotlib\n"
]
}
],
"source": [
"# Imports & Constantes universelles\n",
"%pylab inline\n",
"from matplotlib import animation\n",
"from IPython.display import HTML\n",
"from ipywidgets import interact\n",
"π = np.pi\n",
"μ_0 = 4 * π * 10 ** (-7)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "51eea72db3d546ecb70735d9d0c0b1e3",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(FloatSlider(value=0.2, description='E_0', max=0.6000000000000001, min=-0.2), IntSlider(v…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"<function __main__.effet_de_peau(E_0, f, γ, N, Z, duree)>"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def effet_de_peau(E_0, f, γ, N, Z, duree):\n",
" \"\"\"\n",
" Anime l’évolution temporelle de la pénétration d’un champ dans un matériau:\n",
" - E_0: Amplitude du champ\n",
" - f: fréquence du champ\n",
" - γ: conductivité du matériau\n",
" - N: nombre de vecteurs à afficher\n",
" - Z: profondeur du dernier vecteur dans le matériau\n",
" - duree : intervale de temps écoulé entre deux images successives, en ms\n",
" \"\"\"\n",
" \n",
" def amplitude(t, z):\n",
" \"\"\"\n",
" Calcul de l’amplitude du champ à l’instant t et à une distance z de la surface\n",
" \"\"\"\n",
" ω = 2 * π * f # Pulsation du champ, en rad/s\n",
" δ = sqrt(2 / (μ_0 * γ * ω)) # Épaisseur de peau, en m\n",
" return E_0 * exp(-z / δ) * cos(ω * t + z / δ)\n",
"\n",
" def amplitudes(i, X):\n",
" \"\"\"\n",
" Calcule l’amplitude du champ à une liste de lieux de plus en plus profonds dans le matériau pour l’image i\n",
" \"\"\"\n",
" return [amplitude(i * duree / 1000, z) for z in X]\n",
"\n",
" X = np.linspace(0, Z, N) # Abscisses des vecteurs\n",
" Y = np.zeros(N) # Ordonnées des vecteurs\n",
" U = np.zeros(N) # Amplitude horizontale des vecteurs\n",
" V = amplitudes(0, X) # Amplitude initiale verticale des vecteurs\n",
" fig, ax = plt.subplots()\n",
" Q = ax.quiver(X, Y, U, V, scale=1)\n",
"\n",
" def update_quiver(i, Q):\n",
" V = amplitudes(i, X)\n",
" Q.set_UVC(U, V)\n",
" return Q,\n",
"\n",
" anim = animation.FuncAnimation(fig, update_quiver, fargs=(Q,), interval=50, blit=False)\n",
" return HTML(anim.to_html5_video())\n",
"\n",
"\n",
"interact(effet_de_peau, E_0=0.2, f=10, γ=60*10**6, N=10, Z=0.05, duree=1)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment