2
$\begingroup$

I have written a simple molecular dynamics simulation program. The simulation runs fine but the physical properties (in particular, I have calculated temperature) are off by many scales. I understand that this might be due to not using the proper dimensionless units for the parameters and variables. How should I choose the units? Are there different methods for doing this? I would appreciate if someone could provide a good reference regarding this.

$\endgroup$
6
  • $\begingroup$ What's wrong with using SI units? Since I assume that you are using doubles, the floating point units in your computer's CPU will take care of the scaling for you on the fly. The only reason to rescale yourself would be if you had to do this on integer pipelines in e.g. a GPU. $\endgroup$
    – CuriousOne
    Jun 2, 2015 at 17:02
  • $\begingroup$ @CuriousOne: In many simulations, products of big and small numbers (e.g., $\rho v\approx10^{-24}{\rm\,g/cm^3}\cdot10^9{\rm\,cm/s}$) can lead to floating point precision errors. Making the code non-dimensioned is somewhat tricky but usually necessary to maintain accuracy. This is probably more true for CPUs because the ratio of people using GPUs to CPUs is pretty small. $\endgroup$
    – Kyle Kanos
    Jun 2, 2015 at 17:52
  • 1
    $\begingroup$ Using a set of units appropriate for the problem (which is rarely SI) also has the additional reducing and debugging human error. For example, it is easy to miss a factor of $\hbar$ when programming and then get an answer that is out by a factor of 10$^{-34}$. $\endgroup$ Jun 2, 2015 at 19:13
  • 1
    $\begingroup$ @KyleKanos: With all respect, please read up on floating point error propagation because your example is flat out wrong. Multiplication of numbers with large differences in exponents does not lead to floating point errors. Addition and subtraction of those numbers does, but no amount of normalization can help with that. The correct way to minimize these errors is by using multi-precision arithmetic and to pre-sort the members of sums and differences in such a way that rounding errors are being kept to a minimum. $\endgroup$
    – CuriousOne
    Jun 3, 2015 at 6:40
  • 1
    $\begingroup$ @KylaKanos: Every floating point operation with fixed mantissa length will lead to a loss of precision, but the average loss of precision for multiplications is essentially independent of the numerical values of the exponents, a multiplication with 10 does not result in a pure shift, so there may be an error on the order of 1e-18 for 64 bit mantissa length, unless a numerical over- or underflow occurs. That, of course, is not his problem. His problem is that he has made a mistake in the program. $\endgroup$
    – CuriousOne
    Jun 3, 2015 at 18:22

2 Answers 2

1
$\begingroup$

The possible choices of sets of units for your simulations is probably infinite, so the answer is ultimately going to be choose a set of units that fit what you need & run with it.

For instance, suppose you want to study the Argon interacting via the Lennard-Jones potential, an appropriate choice of units could be mass, $\mu$, length, $\sigma$, and energy, $\varepsilon$ (which would then allow you to define all other relevant scales via products & divisors of the three) with the scales defined as $$ \sigma=3.4\times10^{-10}\,\rm m\\ \mu=6.69\times10^{-26}\,\rm kg\\ \varepsilon=1.65\times10^{-21}\,\rm J $$ all of which are related to the properties of Argon & the L-J potential. If you are studying some other atom/molecule or a different potential, you'll want to scale the different quantities to the properties of the atom/molecule/potential you are interested in.

It might also be worthwhile to look into the literature for the scalings used by other people studying the same thing as you.

I had suggested in another answer that you should be defining your initial conditions in physical units, then scaling them appropriately after the IC has been set. For output/visualization purposes, you would want to re-scale the quantities to have physical values for display.

$\endgroup$
3
  • 1
    $\begingroup$ Good answer, it is worth a comment to make this point totally explicit: the appropriate set of units should make the numerical value of the parameters entering the simulation of order 1, at least insofar as possible. $\endgroup$ Jun 2, 2015 at 20:24
  • $\begingroup$ How should I scale the time and temperature? $\endgroup$ Jun 3, 2015 at 18:01
  • $\begingroup$ @Yogesh: If you used the scales I used, it'd be $t'=t\sigma\left(\mu\varepsilon\right)^{1/2}$ and $T'=T(\varepsilon/k_B)$ (which is easily proved using dimensional analysis). $\endgroup$
    – Kyle Kanos
    Jun 3, 2015 at 18:12
0
$\begingroup$

LAMMPS is a well known molecular dynamics simulation code, here is their documentation on the pages where they discuss units.

http://lammps.sandia.gov/doc/units.html

$\endgroup$
4
  • 1
    $\begingroup$ Welcome to Physics! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. $\endgroup$
    – Kyle Kanos
    Jun 2, 2015 at 17:48
  • $\begingroup$ Thanks for the pointer, I'll keep it in mind for the next time. $\endgroup$
    – Adrian
    Jun 2, 2015 at 18:39
  • 2
    $\begingroup$ Writing an answer on a Stack Exchange site is not a one-time thing. You can edit and improve it. Kyle and fibonatic are suggesting that you do that. $\endgroup$ Jun 2, 2015 at 23:42
  • 4
    $\begingroup$ There's no need to keep it in mind for the next time; you can just edit your answer. $\endgroup$
    – Javier
    Jun 2, 2015 at 23:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.