Last active
December 16, 2015 12:38
-
-
Save andersx/5435486 to your computer and use it in GitHub Desktop.
2D lennard jones simulation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
import random | |
from numba import double # Add this | |
from numba.decorators import autojit, jit # Add this | |
#@jit(argtypes=[double[:], double[:]]) # Add this if you want more speed than autojit | |
@autojit # Add this | |
def calc_energy_and_gradient(X, Y): | |
""" Calculate the Lennard-Jones energy and | |
Energy gradient between particles. | |
X and Y are lists containing x and y | |
coordinates, respectively. | |
""" | |
[ code here ] | |
return energy, gradient | |
n_particles = 16 | |
# Initialize particle coordinates and velocities | |
X = numpy.array([random.random() for i in range(n_particles)]) | |
Y = numpy.array([random.random() for i in range(n_particles)]) | |
# Calculate initial energy and gradient | |
for n in range(10000): | |
energy, gradient = calc_energy_and_gradient(X, Y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment