Re: Performance assistance / advice

"Tim Bradshaw (as tfb at cley dot com)" <[email protected]>
Newsgroups gmane.lisp.lispworks.general
Message-ID <[email protected]>
On 12 Mar 2025, at 11:42, David McClain <[email protected]> wrote:
> 
> Rather than just tackling the obvious “every particle affects every other particle”, I’d want to examine the underlying physics to see if the force law diminishes rapidly enough to where I could get away with restricting examination of particle interactions to some degree of nearest neighbors.

Gravity is famously long-range and always attractive: that's why the universe is the way it is on large scales and why books with titles like 'The large scale structure of spacetime' are really books on gravitation.

Integrating gravitational systems is famously a hard problem.  I don't know the state of the art or anything near it, but a long-ago trick is that you can assume the field from distant objects changes only rather slowly, so you can use multiple time steps after grouping things.  I am sure there are much cleverer approaches today: I think the term to search for is 'symplectic integrator'.

But it does actually matter, and there's a lovely example of how much.  You have a billiard-ball classical gas in an ideal box, in an otherwise empty universe (so what you have to do is just simulate the collisions of the particles with each other and the walls of the box).  So, OK, you can simulate that and it's completely deterministic as you'd expect (you are allowed to use arbitrary numerical precision and arbitrary amounts of computer time, you can know the initial conditions as exactly as you like).

Except it turns out the universe is not quite empty:  there is a stray electron (for the sake of this thought experiment it can be assumed to be electrically neutral, but have the mass of an electron) which is 10 billion light years away but you don't know in which direction.  So your simulation can't model the gravitational influence of this particle on your little box of gas.

We'll say that your simulation has definitively failed when a particle leaves a collision 90 degrees away from the angle you predicted.  For a given particle, how many collisions can you now predict forward before the simulation fails?

About 40.  So a tiny fraction of a microsecond.

Well, this is really a demonstration of how quickly systems with SDIC become unpredictable, and of course your simulation will continue to correctly predict the macroscopic properties of the gas.  But still.

But that's not the point.  My simulation is *not meant to be anything which an astrophysicist would use to simulate the evolution of a galaxy*.  It is meant, instead, to be a well-defined numerical algorithm, which I could then use to look at performance.  As I wrote in my original message:

> I wrote some code which, very naïvely, evolves a system of gravitating particles. 'Very naively' means: calculate the accelerations of each particle based on all the other particles and then step positions and velocities.  This is quadratic in particle number and not how people integrate things like models of galaxies, but I don't care: I just wanted a well-defined algorithm.

--tim


_______________________________________________
Lisp Hug - the mailing list for LispWorks users
[email protected]
http://www.lispworks.com/support/lisp-hug.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.