Sciencemadness Discussion Board
Not logged in [Login ]
Go To Bottom

Printable Version  
Author: Subject: what is wrong with my molecular dynamics program? lennard-jones potential simulator
Cou
National Hazard
****




Posts: 958
Registered: 16-5-2013
Member Is Offline

Mood: Mad Scientist

[*] posted on 20-10-2018 at 09:38
what is wrong with my molecular dynamics program? lennard-jones potential simulator


EDIT: solved, made the derpy mistake of not clearing accelerations between each step

This isn't for homework, I'm trying to make a user-friendly program for simple molecular dynamics so I can simulate the physical dynamics of radioactive decay (e.g. what would it look like if you had a solid mass gradually decay into a liquid, how do solid radon progeny accumulate, what does it look like when a solid turns spongy due to helium from alpha decay forming gas pockets) its for my own curiosity, im only a college freshman. Also if you can find any material on the physical dynamics of radioactive decay I'd like to read it



Here is the function that computes forces between two particles, and the leapfrog integration function: https://pastebin.com/Z1wTFcax

When I apply the forces to particle velocities, the program seems to work as expected. Results: https://i.imgur.com/i2ZADXS.png

But this is what happens when I make the force apply to acceleration instead of velocity, which is how it's supposed to work. I even tried a slower timestep and the simulation still explodes like this: https://i.imgur.com/Hcgg7o8.png



I haven't taken a physics class in a long time, so I feel like this could be a derpy simple mistake like an issue with calculating the X and Y vectors: forces.x = dist.x / r * force; forces.y = dist.y / r * force;

[Edited on 20-10-2018 by Cou]
View user's profile View All Posts By User
Heptylene
Hazard to Others
***




Posts: 319
Registered: 22-10-2016
Member Is Offline

Mood: No Mood

[*] posted on 20-10-2018 at 14:45


How do you handle the graphics end? Do you use something like SFML?
View user's profile View All Posts By User
Cou
National Hazard
****




Posts: 958
Registered: 16-5-2013
Member Is Offline

Mood: Mad Scientist

[*] posted on 20-10-2018 at 16:09


Quote: Originally posted by Heptylene  
How do you handle the graphics end? Do you use something like SFML?


This is the output of the program: https://www.youtube.com/watch?v=DfeuMCxHUy8

Im only doing this program for fun, I'm only a college freshman I plan to major in chemistry and minor in computer science since i like this kind of stuff

The code directly writes .ppm images, the simplest image format which is just RGB numbers, and I use a screen recorder to capture an image viewer as it slides thru the images (a very duct-tape way of doing it, i can't control the FPS, but I dunno how to program gifs or more advanced software)



[Edited on 21-10-2018 by Cou]
View user's profile View All Posts By User
Cou
National Hazard
****




Posts: 958
Registered: 16-5-2013
Member Is Offline

Mood: Mad Scientist

[*] posted on 21-10-2018 at 14:01


Quote: Originally posted by Heptylene  
How do you handle the graphics end? Do you use something like SFML?


EDIT: I now use a better rendering procedure

1: the program outputs a PPM image file for each frame (wrote a routine to write images bit by bit
2: use XNview to convert the PPM images to PNG
3: use ffmpeg to make a video from the frames

result: https://www.youtube.com/watch?v=Xy_5W1KUymU

[Edited on 21-10-2018 by Cou]
View user's profile View All Posts By User
Texium
Administrator
Thread Moved
21-10-2018 at 18:12
Heptylene
Hazard to Others
***




Posts: 319
Registered: 22-10-2016
Member Is Offline

Mood: No Mood

[*] posted on 22-10-2018 at 13:34


Thanks! Its really neat how the atoms form a close-packed structure as a result of the simple rules governing their motion!
View user's profile View All Posts By User

  Go To Top