MD: Lennard Jones Hi: Troubleshooting Divergences in Simulations

  • Context: Graduate 
  • Thread starter Thread starter JorisL
  • Start date Start date
Click For Summary
SUMMARY

The forum discussion centers on troubleshooting divergences in simulations of Lennard-Jones fluids using MATLAB. The user encountered NaN values due to infinite forces arising when particles come too close together. The divergence persisted despite attempts to adjust the timestep and the addition of thermostat code. A previous issue with periodic boundary conditions was resolved by applying the nearest image convention, which highlights the importance of proper initialization in simulation setups.

PREREQUISITES
  • Understanding of Lennard-Jones potential and its mathematical formulation
  • Familiarity with MATLAB programming and debugging techniques
  • Knowledge of periodic boundary conditions in molecular simulations
  • Experience with numerical methods for simulating particle dynamics
NEXT STEPS
  • Investigate MATLAB's error handling for NaN values in simulations
  • Learn about implementing nearest image conventions in periodic boundary conditions
  • Explore techniques for managing particle collisions in molecular dynamics
  • Study the effects of timestep adjustments on simulation stability
USEFUL FOR

Researchers and developers working in computational physics, particularly those focused on molecular dynamics simulations and the behavior of fluids at the atomic level.

JorisL
Messages
489
Reaction score
189
Hi

For a simulation regarding Lennard Jones fluids I'm getting divergences.
I have particles in a fixed volume.
I calculate distances between these particles to find the force.

However in the first iteration I already get divergences (NaN values in matlab).
I use F_x^{ij} = 24\varepsilon \left( 2r_{ij}^{-14}-r_{ij}^{-8}\right)\cdot \Delta x_{ij}
Where the i,j have to do with the particles I'm viewing. For each direction I get such a force.
But some of the particles get so close that this force and hence the acceleration effectively become infinity. My simulation obviously breaks down at this point.

I tried changing the timestep, this doesn't do anything.
It worked at some point but I don't recall changing anything after that. Except adding the thermostat code which I can turn off. The divergence remains.

You can find my (messy) code in this pastebin http://pastebin.com/62v1yTCY
I've been looking at it for hours already yet I can't find any solution.

JorisL

Edit;
I had divergences before. Those were caused by an error in applying the periodic boundary conditions. I forgot using the nearest image convention at that time.
 
Last edited:
Physics news on Phys.org
I found the mistake.
In my initialization of the cubic lattice, I had a break off variable g.
I initialized this one as g = 1. Which caused the last point to to coincide with my first point and so I got immediate divergences.

At least 4 hours to waste :S

J
 
You may have wasted 4 hours on this, but it took you 20+ years to get to this point...
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
8K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 21 ·
Replies
21
Views
4K
  • · Replies 7 ·
Replies
7
Views
7K