# How does Temperature work in particle-based simulations?

I've seen a number of particle based simulations of things like magnets settling or crystaline structure forming or other phase transitions assosciated with temperature. I can kind of accept that an increase in temperature could be modelled by boosting the velocity of random particles, but that doesn't seem very physical, and if thermal motion is supposed to be random, does that necessarily mean that you can't just increase the speed, you have to change the direction too? Also, how does one arrive at a Blackbody distribution of energies by doing this?

I thought that maybe a way to do it would be to "shake the container" so that particles bouncing off the walls would have a random change in their velocity but that feels like it could decrease energy as often as it increased it. It does have the advantage of representing the particles interacting with something "outside the system" in order to gain and lose energy.

I understand how to calculate the temperature once I have the simulation, but I don't understand how I can change the temperature in a physically accurate way.

(Also I understand that the temperature would remain constant during changes of phase so that's not really important. I suppose my real question is how to add/remove Thermal Energy to a system being simulated as either hard-sphere particles or some kind of simple power law type interaction like Lennard-Jones or Ionic.)

• The folks over at Matter Modeling SE have plenty of relevant experience here. But note that for heat transfer to occur at the walls of a container, a random amount of energy is added/subtracted during collisions (and it is both added and subtracted, just more is added if heat is flowing in vs out). Commented Aug 3, 2022 at 13:37
• I had no idea there was such a stack-exchange. Thanks for letting me know. Could you perhaps link a question on there that's particularly relevant? Commented Aug 3, 2022 at 13:43
• Something like mattermodeling.stackexchange.com/questions/9374/… gets into the nitty-gritty pretty quickly... Commented Aug 3, 2022 at 13:51