#!/usr/bin/env python # -*- coding: utf-8 -*- """ KdV_DeuxSolitonAnalytique.py Simulation de la collision élastique de deux solitons KdV """ __author__ = "Dominique Lefebvre" __copyright__ = "Copyright 2020 - TangenteX.com" __version__ = "1.0" __date__ = "8 novembre 2020" __email__ = "dominique.lefebvre@tangentex.com" from scipy import cosh, sqrt, linspace from matplotlib.pyplot import figure,plot,xlim,ylim,grid,title,xlabel,ylabel,show import matplotlib.animation as animation # Fonction sécante hyperbolique def sech(x): y = 1./cosh(x) return y # Solution analytique de l'équation KdV def KdVAnalytique(x,t,c,x0): u = (c/2.)*sech((sqrt(c)/2.)*(x - c*t - x0))**2 return u # Définition du domaine spatial L = 80.0 # période spatiale N = 256 # nombre de pas de discrétisation du domaine spatial x0 = 0 x = linspace(x0, L, N) # parametres temporels t0 = 0 dt = 0.01 # paramètres animation interval_image = 1 # intervalle entre deux images exprimé en ms nb_images = 3000 # nombre d'iamges de l'animation # Définition des conditions initiales c1 = 0.5; shift1 = 0.3*L # soliton initial 1 c2 = 2.0; shift2 = 0.05*L # soliton initial 2 def init(): line.set_data([],[]) return line, # fonction de tracé de l'animation def KdV(i): t =i*dt y = KdVAnalytique(x,t,c1,shift1) + KdVAnalytique(x,t,c2,shift2) line.set_data(x,y) return line, # tracé de l'évolution fig1 = figure(figsize=(8,6)) line, = plot([],[]) xlim(0,L) ylim(0.0,1.5) grid(True) title("Solitons de Korteweg de Vries - Collision de solitons") xlabel("X") ylabel("U(x,t)") # lancement animation ani = animation.FuncAnimation(fig1,KdV,init_func=init,frames=nb_images, interval= interval_image,blit=True, repeat=False) show()