In [1]:
%load_ext autoreload
%autoreload 2
In [2]:
import elasticite as el
import numpy as np
np.set_printoptions(precision=2, suppress=True)
import matplotlib.pyplot as plt
In [3]:
class EdgeGrid(el.EdgeGrid):
def update_particles(self):
self.particles[2,:] = np.cos((self.t + np.linspace(0, 1., self.N_particles))*2*np.pi)
def update(self):
self.update_particles()
e = EdgeGrid(N_lame=25, grid_type='line')
e.animate()
Out[3]:
In [4]:
CC = e.particles[:, :, np.newaxis]-e.particles[:, np.newaxis, :] # 2xNxN ; en metres
distance = np.sqrt(np.sum(CC**2, axis=0))# NxN ; en metres
print(distance)
print(np.tanh(np.linspace(-2, 2, 15)))
d_min, d_max = .2, 1.
f = lambda d: 900./ e.N_particles* (np.exp(-d/d_max)/d_max - np.exp(-d/d_min)/d_min)
print(f(np.linspace(0, 2, 15)))
In [5]:
class EdgeGrid(el.EdgeGrid):
def update_particles(self):
CC = self.particles[:, :, np.newaxis]-self.particles[:, np.newaxis, :] # 2xNxN ; en metres
distance = np.sqrt(np.sum(CC**2, axis=0))# NxN ; en metres
d_min, d_max = .2, 1.5
#f = lambda d: -100./ self.N_particles* (np.exp(-d/d_max)/d_max - np.exp(-d/d_min)/d_min)
#f = lambda d: 100./ self.N_particles* (np.exp(-d/d_max) - np.exp(-d/d_min))
f = lambda d: -20./ self.N_particles* (np.exp(-d/d_max)/d_max - np.exp(-d/d_min)/d_min)
#R = lambda w: - 3.5*np.sin(2*np.pi*w)
#R = lambda w: w*(1 - w**2)
R = lambda w: .2*np.tanh(w) # (1+w)*(1-w)
w = self.particles[2,:]
#print('w_t', (np.dot(f(distance), w)).mean(), (np.dot(f(distance), w)).std())
#w *= (1-self.dt)
w += np.tanh(np.dot(f(distance), w) + R(w))*self.dt
#print(w.min(), w.max())
#w /= np.absolute(w).max()
self.particles[2,:] = w
def update(self):
self.update_particles()
e = EdgeGrid(N_lame=25, grid_type='line')
#e.particles[2, :] = 0
#e.particles[2, 0] = -1.
#e.particles[2, -1] = 1.
#e.particles[2, :] = 2*np.random.rand(e.N_particles)-1
e.animate(duration=40, fps=10, fname='../files/reaction-diffusion.mp4')
Out[5]:
In [6]:
class EdgeGrid(el.EdgeGrid):
def update_particles(self):
CC = self.particles[:, :, np.newaxis]-self.particles[:, np.newaxis, :] # 2xNxN ; en metres
distance = np.sqrt(np.sum(CC**2, axis=0))# NxN ; en metres
d_min, d_max = .2, 1.5
#f = lambda d: -100./ self.N_particles* (np.exp(-d/d_max)/d_max - np.exp(-d/d_min)/d_min)
#f = lambda d: 100./ self.N_particles* (np.exp(-d/d_max) - np.exp(-d/d_min))
f = lambda d: 20./ self.N_particles* (np.exp(-d/d_max)/d_max - np.exp(-d/d_min)/d_min)
#R = lambda w: - 3.5*np.sin(2*np.pi*w)
#R = lambda w: w*(1 - w**2)
R = lambda w: -10.*np.tanh(w) # (1+w)*(1-w)
w = self.particles[2,:]
#print('w_t', (np.dot(f(distance), w)).mean(), (np.dot(f(distance), w)).std())
#w *= (1-self.dt)
w += np.tanh(np.dot(f(distance), w) + R(w))*self.dt
#print(w.min(), w.max())
#w /= np.absolute(w).max()
self.particles[2,:] = w
def update(self):
self.update_particles()
e = EdgeGrid(N_lame=25, grid_type='line')
#e.particles[2, :] = 0
#e.particles[2, 0] = -1.
#e.particles[2, -1] = 1.
#e.particles[2, :] = 2*np.random.rand(e.N_particles)-1
e.animate(duration=40, fps=10, fname='../files/reaction-diffusion-up.mp4')
Out[6]:
In [7]:
class EdgeGrid(el.EdgeGrid):
def update_particles(self):
CC = self.particles[:, :, np.newaxis]-self.particles[:, np.newaxis, :] # 2xNxN ; en metres
distance = np.sqrt(np.sum(CC**2, axis=0))# NxN ; en metres
d_min, d_max = .2, 1.5
#f = lambda d: -100./ self.N_particles* (np.exp(-d/d_max)/d_max - np.exp(-d/d_min)/d_min)
#f = lambda d: 100./ self.N_particles* (np.exp(-d/d_max) - np.exp(-d/d_min))
f = lambda d: 20./ self.N_particles* (np.exp(-d/d_max)/d_max - np.exp(-d/d_min)/d_min)
#R = lambda w: - 3.5*np.sin(2*np.pi*w)
#R = lambda w: w*(1 - w**2)
R = lambda w: -10.*np.tanh(w) # (1+w)*(1-w)
w = self.particles[2,:]
#print('w_t', (np.dot(f(distance), w)).mean(), (np.dot(f(distance), w)).std())
#w *= (1-self.dt)
w += np.tanh(np.dot(f(distance), w) + R(w))*self.dt
#print(w.min(), w.max())
#w /= np.absolute(w).max()
self.particles[2,:] = w
def update(self):
self.update_particles()
e = EdgeGrid(N_lame=25, grid_type='line')
#e.particles[2, :] = 0
#e.particles[2, 0] = -1.
#e.particles[2, -1] = 1.
#e.particles[2, :] = 2*np.random.rand(e.N_particles)-1
e.animate(duration=40, fps=10, fname='../files/reaction-diffusion-up.mp4')
Out[7]:
In [8]:
!git s
In [9]:
!git commit -am' expansion - équation de reaction diffusion'
In [10]:
! git push
In [11]:
!git pull