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()


WARNING:py.warnings:/usr/local/lib/python3.5/site-packages/skimage/filter/__init__.py:6: skimage_deprecation: The `skimage.filter` module has been renamed to `skimage.filters`.  This placeholder module will be removed in v0.13.
  warn(skimage_deprecation('The `skimage.filter` module has been renamed '

[MoviePy] >>>> Building video /var/folders/3p/m0g52j9j69z3gj8ktpgg1dm00000gn/T/tmp7y3156zn.mp4
[MoviePy] Writing video /var/folders/3p/m0g52j9j69z3gj8ktpgg1dm00000gn/T/tmp7y3156zn.mp4
  9%|▉         | 19/201 [00:03<00:30,  5.89it/s]WARNING:py.warnings:/usr/local/lib/python3.5/site-packages/matplotlib/pyplot.py:516: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  max_open_warning, RuntimeWarning)

                                                 
[MoviePy] Done.
[MoviePy] >>>> Video ready: /var/folders/3p/m0g52j9j69z3gj8ktpgg1dm00000gn/T/tmp7y3156zn.mp4 


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)))


[[ 0.    0.43  0.87 ...,  6.72  7.02  7.34]
 [ 0.43  0.    0.43 ...,  6.87  7.15  7.46]
 [ 0.87  0.43  0.   ...,  7.04  7.31  7.59]
 ..., 
 [ 6.72  6.87  7.04 ...,  0.    0.44  0.88]
 [ 7.02  7.15  7.31 ...,  0.44  0.    0.44]
 [ 7.34  7.46  7.59 ...,  0.88  0.44  0.  ]]
[-0.96 -0.94 -0.89 -0.82 -0.69 -0.52 -0.28  0.    0.28  0.52  0.69  0.82
  0.89  0.94  0.96]
[-75.   -29.64  -8.38   1.22   5.2    6.54   6.67   6.27   5.67   5.03
   4.42   3.86   3.36   2.92   2.53]

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')


WARNING:py.warnings:/usr/local/lib/python3.5/site-packages/matplotlib/pyplot.py:516: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  max_open_warning, RuntimeWarning)

[MoviePy] >>>> Building video ../files/reaction-diffusion.mp4
[MoviePy] Writing video ../files/reaction-diffusion.mp4
                                                 
[MoviePy] Done.
[MoviePy] >>>> Video ready: ../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')


WARNING:py.warnings:/usr/local/lib/python3.5/site-packages/matplotlib/pyplot.py:516: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  max_open_warning, RuntimeWarning)

[MoviePy] >>>> Building video ../files/reaction-diffusion-up.mp4
[MoviePy] Writing video ../files/reaction-diffusion-up.mp4
                                                 
[MoviePy] Done.
[MoviePy] >>>> Video ready: ../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')


WARNING:py.warnings:/usr/local/lib/python3.5/site-packages/matplotlib/pyplot.py:516: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  max_open_warning, RuntimeWarning)

[MoviePy] >>>> Building video ../files/reaction-diffusion-up.mp4
[MoviePy] Writing video ../files/reaction-diffusion-up.mp4
                                                 
[MoviePy] Done.
[MoviePy] >>>> Video ready: ../files/reaction-diffusion-up.mp4 


Out[7]:

git


In [8]:
!git s


 D 14-06-25-animation-in-a-notebook.ipynb
A  2014-06-25-animation-in-a-notebook.ipynb
A  2014-06-25-grille-hexagonale.ipynb
 M "2015-10-27 \303\251lasticit\303\251 expansion-r\303\251action diffusion.ipynb"
 M "2015-11-17 \303\251lasticit\303\251 expansion en miroir - dynamique d'un point focal.ipynb"

In [9]:
!git commit -am' expansion - équation de reaction diffusion'


[master 615b95b]  expansion - équation de reaction diffusion
 4 files changed, 1044 insertions(+), 394 deletions(-)
 rename posts/{14-06-25-animation-in-a-notebook.ipynb => 2014-06-25-animation-in-a-notebook.ipynb} (99%)
 create mode 100644 posts/2014-06-25-grille-hexagonale.ipynb
 rewrite "posts/2015-10-27 \303\251lasticit\303\251 expansion-r\303\251action diffusion.ipynb" (96%)

In [10]:
! git push


Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 22.50 MiB | 10.98 MiB/s, done.
Total 7 (delta 2), reused 0 (delta 0)
To git@git.framasoft.org:laurentperrinet/elasticte.git
   58fd2ca..615b95b  master -> master

In [11]:
!git pull


Already up-to-date.