Related sites: | site map |

# aiju.de Home of aiju

- › about me/
- › b/
- » code/
- - › RatJS
  - › homework/
  - » k/
  - - › cluster
    - › coins
    - › eratothenes
    - › euler phi
    - › feigenbaum
    - › fibonacci
    - › fsm
    - » molecule
    - › pascal
    - › qsort
    - › sierpinski
    - › tictactoe
  - › misc/
  - › pdp11/
- › donate
- › electronics/
- › legal
- › misc/
- › plan 9/

# Simulation of Molecular Dynamics

This program simulates a microscopic (25 atoms) portion of a gas like Argon:

    n:5
    v0:2
    dt:0.01
    N:n*n
    P:,/(0.5*(n;n)_draw 0)+{x{[y;z](y;z)}/:\:x}2*(!n)
    V:v0*2*(((N;2)_draw 0)-0.5)
    R:{[p]p{_sqrt+/_sqr(x-y)}/:\:p}
    NV:{[p](p{x-y}/:\:p)%R[p]}
    F:{[p]24*((2%R[p]^13)-1%R[p]^7)*NV[p]}
    TF:{[p]+/+{1_(x?(0n;0n))!x}'F[p]}
    st:{[S] ne:((2*S[0])-S[1])+(_sqr dt)*TF[S[0]]
        (ne;S[0];(ne-S[1])%(2*dt))}
    res:($*:'st\[2000;(P;P-V*dt;V)])
    `0:(|1_|"plot ",,/{[x]"\"-\" u 1:2 w d,"}'(!N)),"\n"
    {`0:(,/'" ",''res@\:x),,,"e"}'(!N)

Since neither walls nor boundary conditions are used, the gas will expand indefinitely. I might add boundary conditions eventually, but the program isn't particularly efficient anyway (read: it's highly inefficient).