Slide for Workshop on Biophysics, Room D, 10.00-12.00, Friday, 9 August 2019 in 17th SEACOMP 2019 & 3rd PIT-FMB 2019, 8-10 August 2019, Badung, Indonesia
Diffusion Simulation with JS: Writing Your Own ABM Code
1. 17th SEACOMP 2019
3rd PIT-FMB 2019
8-10 August 2019, Badung, Indonesia 1
Diffusion Simulation with JS:
Writing Your Own ABM Code
S. Viridi1
, F. Haryanto1
, A. Sutresno2
, I. Arif1
1
Department of Physics, Institut Teknologi Bandung, Bandung 40132 Indonesia
2
Department of Physics, Universitas Kristen Satya Wacana, Salatiga 50711, Indonesia
v201890808_2
2. This slide is part of
17th SEACOMP 2019
3rd PIT-FMB 2019
8-10 August 2019, Badung, Indonesia 2
3. 17th SEACOMP 2019
3rd PIT-FMB 2019
8-10 August 2019, Badung, Indonesia 3
Outline
• Introduction
• Agent-based model (ABM)
• JavaScript (JS) implementation
• Discussion
4. 17th SEACOMP 2019
3rd PIT-FMB 2019
8-10 August 2019, Badung, Indonesia 4
Introduction
5. Fick’s law
• Original form
• If container cross-section Q is not function of
x
which is the well-known form, Fick’s 2nd law
17th SEACOMP 2019
3rd PIT-FMB 2019
8-10 August 2019, Badung, Indonesia 5
( ) ( )
2
2
,,
x
txC
D
t
txC
∂
∂
−=
∂
∂
( ) ( ) ( )
∂
∂
+
∂
∂
−=
∂
∂
x
txC
dx
dQ
Qx
txC
D
t
txC ,1,,
2
2
A. Fick, "Über Diffusion", Annalen der Physik [Ann. Phys. (Leipzig)], vol. 170, no. 1, pp. 59-86, 1855, url
https://doi.org/10.1002/andp.18551700105
6. Modification
• In order to accomodate finite-time limit, non-
Gaussian distribution, Burnett coefficients,
previous equation will be generalized into
which is reduced to Fick’s 2nd law if N = 1 and
t′ = 0, where φ2 is distribution change kernel
17th SEACOMP 2019
3rd PIT-FMB 2019
8-10 August 2019, Badung, Indonesia 6
W. E. Alley, B. J. Alder, "Modification of Fick's Law", Physical Review Letters [Phys. Rev. Lett.] vol. 43, no. 10, pp. 653-
656, Sep 1979, url https://doi.org/10.1103/PhysRevLett.43.653
( ) ( ) ( )
n
nN
n
t
n
x
txC
tttd
D
D
t
txC
2
2
1 0
2
2 ,,
∂
′∂
′−′−=
∂
∂
∑ ∫=
ϕ
7. Numerical approach: FD
• With finite difference method, partial
differen-tial equation related to diffusion can
be solved
• And the Fick’s 2nd law will be
with j is for time and i is for position
17th SEACOMP 2019
3rd PIT-FMB 2019
8-10 August 2019, Badung, Indonesia 7
J. C. Wu, N. A. Peppas, "Numerical Simulation of Anomalous Penetrant Diffusion in Polymers", Journal of Applied
Polymer Science [J. Appl. Polym. Sci.], vol. 49, no. 10, pp. 1845-1856, Sep 1993, url
https://doi.org/10.1002/app.1993.070491015
( ) ( ) j
i
j
i
j
i
j
i
j
i
j
i CCC
x
tD
CC
x
tD
C +−
∆
∆
−−
∆
∆
−= −+
+
1212
1
8. Illustration of FD approach
17th SEACOMP 2019
3rd PIT-FMB 2019
8-10 August 2019, Badung, Indonesia 8
9. 17th SEACOMP 2019
3rd PIT-FMB 2019
8-10 August 2019, Badung, Indonesia 9
Agent-based model
10. Agents as particles
• An agent will represent a particle
• Various behaviours can be defined, even the
not physical ones
• The freedom of this model is an advantage
17th SEACOMP 2019
3rd PIT-FMB 2019
8-10 August 2019, Badung, Indonesia 10
11. Previous work
• ABM has been implemented using matrix
representation to simulate diffusion of gas
and fluid
17th SEACOMP 2019
3rd PIT-FMB 2019
8-10 August 2019, Badung, Indonesia 11
S. Viridi, Z. F. T. W. Lestari, T. D. K. Wungu, Suprijadi, "Simple Grid-Based Model of Sandpile Avalanche Due to
Heating Process", International Workshop on Computational Science, 30 June 2018, Kanazawa University, Japan, url
https://doi.org/10.17605/osf.io/nker6
12. Previous work: Initial condition
• System grid (square with blue line) with object
grid (black rectangle)
17th SEACOMP 2019
3rd PIT-FMB 2019
8-10 August 2019, Badung, Indonesia 12
13. • p← = –1, p→ = +1
• p↑ = +1, p↓ = –1
Previous work: Gas phase
17th SEACOMP 2019
3rd PIT-FMB 2019
8-10 August 2019, Badung, Indonesia 13
t = 0.01 t = 0.04 t = 0.2
14. • p← = –1, p→ = +1
• p↑ = +0.5, p↓ = –1
Previous work: Fluid phase
17th SEACOMP 2019
3rd PIT-FMB 2019
8-10 August 2019, Badung, Indonesia 14
t = 0.01 t = 0.1 t = 0.2
15. 17th SEACOMP 2019
3rd PIT-FMB 2019
8-10 August 2019, Badung, Indonesia 15
JS Implementation
16. World matrix W
• Matrix that represents static boundary
condition
• Value of 0: free space, where agents can move
into
• Value of 1: occupied space, where agent are
not allowed to move into
17th SEACOMP 2019
3rd PIT-FMB 2019
8-10 August 2019, Badung, Indonesia 16
17. Agent matrix A
• Matrix that represents position of all agents
• It will have value from 2 to N + 1, where N is
types of agents
• Each type is related to specific diffusion
coefficient D, which indicates how active one
type can be
17th SEACOMP 2019
3rd PIT-FMB 2019
8-10 August 2019, Badung, Indonesia 17
18. Algorithm
• Step 1 t = tbeg
• Step 2 Choose not empty element in A
• Step 3 Generate new position using D
• Step 4 Move agent if destination value is 0
• Step 5 Repeat Step 2 for all agents
• Step 6 t = t + Δt
• Step 7 If t < tend Repeat Step 2
17th SEACOMP 2019
3rd PIT-FMB 2019
8-10 August 2019, Badung, Indonesia 18
19. JavaScript implementation
• url https://bit.do/workshop-biophysics
17th SEACOMP 2019
3rd PIT-FMB 2019
8-10 August 2019, Badung, Indonesia 19
23. JS implementation (cont.)
• In a web browser, use CTRL + U to see the
code
• You can modify the code and implement in
your own way
17th SEACOMP 2019
3rd PIT-FMB 2019
8-10 August 2019, Badung, Indonesia 23
25. 17th SEACOMP 2019
3rd PIT-FMB 2019
8-10 August 2019, Badung, Indonesia 25
Discussion
26. Discussion
• Any suggestion?
• Any idea for collaboration?
• Source is avalable at
https://github.com/dudung/butiran.js
17th SEACOMP 2019
3rd PIT-FMB 2019
8-10 August 2019, Badung, Indonesia 26