MD: Lennard Jones Hi: Troubleshooting Divergences in Simulations

  • Thread starter JorisL
  • Start date
In summary, the conversation discusses a simulation involving Lennard Jones fluids where the speaker is experiencing divergences, or NaN values, in their calculations. They are using a formula to calculate the force between particles and have tried changing the timestep and adding a thermostat code, but the divergences remain. The speaker shares a link to their code and mentions a previous mistake with periodic boundary conditions. After further investigation, they realize that their initialization of a variable caused the issue and have now solved the problem. The conversation ends with the speaker reflecting on the time spent on this issue.
  • #1
JorisL
492
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 [tex]F_x^{ij} = 24\varepsilon \left( 2r_{ij}^{-14}-r_{ij}^{-8}\right)\cdot \Delta x_{ij}[/tex]
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
  • #2
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
 
  • #3
You may have wasted 4 hours on this, but it took you 20+ years to get to this point...
 

1. What is MD simulation?

MD simulation stands for Molecular Dynamics simulation. It is a computational technique used in the field of theoretical chemistry to study the motion and behavior of atoms and molecules.

2. What is the Lennard Jones potential?

The Lennard Jones potential is a mathematical model used to describe the interaction between non-bonded atoms or molecules. It takes into account both the attractive and repulsive forces between particles, and is commonly used in MD simulations to calculate the potential energy of a system.

3. What are divergences in MD simulations?

In MD simulations, divergences refer to situations where the simulated behavior of the system does not match the expected behavior based on the input parameters and physical laws. This can lead to inaccurate or unreliable results.

4. How can I troubleshoot divergences in MD simulations?

To troubleshoot divergences in MD simulations, first check for any errors in the input parameters or code. Then, try adjusting the simulation parameters such as time step, temperature, or pressure. It may also be helpful to visualize the trajectory of the simulation and identify any unusual behavior. If the issue persists, consult with other experts or refer to literature for similar cases.

5. How can I prevent divergences in MD simulations?

To prevent divergences in MD simulations, it is important to carefully choose the simulation parameters and validate them with experimental data or results from previous simulations. It is also helpful to use multiple simulation techniques and compare the results to ensure accuracy. Additionally, regularly checking and updating the simulation code can help prevent any errors or bugs that may cause divergences.

Similar threads

  • Atomic and Condensed Matter
Replies
1
Views
1K
  • Atomic and Condensed Matter
Replies
1
Views
2K
  • Programming and Computer Science
Replies
2
Views
7K
  • Mechanical Engineering
Replies
2
Views
1K
Replies
2
Views
3K
  • Advanced Physics Homework Help
Replies
1
Views
1K
  • Programming and Computer Science
Replies
4
Views
1K
  • Atomic and Condensed Matter
Replies
2
Views
1K
  • Advanced Physics Homework Help
Replies
1
Views
1K
  • Programming and Computer Science
Replies
1
Views
6K
Back
Top