Getting Started with C++ (for N-Body Simulations)

Click For Summary
SUMMARY

To get started with C++ programming for N-body simulations, one should focus on understanding parallel programming concepts and numerical methods. The discussion emphasizes the importance of utilizing libraries such as OpenGL for visualization and Octrees for optimizing computational efficiency. Additionally, resources like Hockney's "Computational Simulations using Particles" and Open Source Physics provide foundational knowledge and practical tools for simulation development. The choice of C++ is often driven by the need for speed in execution compared to languages like Python or Java.

PREREQUISITES
  • Basic understanding of C++ programming and syntax
  • Familiarity with parallel programming concepts, particularly OpenMP
  • Knowledge of numerical methods for simulations
  • Experience with OpenGL for graphical visualization
NEXT STEPS
  • Explore C++ libraries for numerical simulations, focusing on OpenGL for visualization
  • Learn about Octree data structures and their implementation in C++ for efficient spatial partitioning
  • Research parallel computing techniques using OpenMP to enhance simulation performance
  • Study Hockney's "Computational Simulations using Particles" for theoretical insights and practical applications
USEFUL FOR

Researchers, physicists, and developers interested in computational simulations, particularly those focusing on N-body problems and requiring high-performance computing solutions.

allazar
Messages
4
Reaction score
0
Hello all. I don't really know what to exactly ask from any of you other than how I should get started with C++ programming to hopefully create N-body simulations down the road. How to exactly start, I'm not entirely sure.

For a little about what I know, I know python extensively. I use it almost everyday for data analysis in my research and I can create programs that coincide with numerical computations. But that is just about it.

I have some knowledge on how C++ works, but not concretely (ie parallel programming??). Python can be simple in the case of just downloading and importing packages like numpy, scipy, or astropy to do data analysis, but for C++, i have no idea where to start on this (my apologies for reiterating this). In particular, I'm interested in devising N-body simulations and everything implemented with it (numerical solving and visualization). I have Hockney's "Computational Simulations using Particles" that goes over the theory, but all I have left is to just apply it.

How should I go about achieving my goals? What should I look into? What should I download.
 
Technology news on Phys.org
My first question is why have you chosen C/C++ as the language of choice?

There are many good references on N-body simulations that use Java and Python. Are you interested in "speed" of execution or is it because of some class requirement?

Assuming that language is not really the issue then I would suggest looking at Open Source Physics. Its a collection of java classes for writing complex simulations such as N-body simulations. It comes with several ODE solvers, and many 2D and 3D graphical plotting classes. THe authors have also written a book covering a lot of simulation material including and going beyond N-body.

www.compadre.org/osp

and the book

http://www.compadre.org/OSP/document/ServeFile.cfm?ID=7375&DocID=527

If instead you want ot use Python then the Anaconda version has numpy, and scipy included:

http://lectures.quantecon.org/

for directions on how to install and use it.

Alternatively you could consider using julia (see the above link) which is a MATLAB like clone as the programming language of choice

https://www.wired.com/2014/02/julia/

Lastly, you could look as Processing.org, a java language environment with extensive graphics libraries, examples and tutorials to get you up and running with Java. Some examples could be adapted to the N-body problem if they don't simulate it already.



Processing makes the power of OpenGL available to you via the java language so give it a try.

processing.org
 
  • Like
Likes   Reactions: QuantumQuest, Hesch and S.G. Janssens
To add to my previous post, Processing has a contributed library called PixelFlow which has some fantastic particle system examples which you should definitely checkout.

His github page has several videos to check out:

https://github.com/diwi/PixelFlow

The source code is here:

http://thomasdiewald.com/processing/libraries/pixelflow/

to run any examples:
- download processing,
- install it and
- from the Sektch>>Import Libraries...>>Add Library option,
- select this library to install it.
- then File>>Examples>>PixelFlow select an example.

One example, I've run recently is Softbody2D_ParticleSystems which interacts with the mouse and sloshes a bunch of variously sized particles around.
 
  • Like
Likes   Reactions: S.G. Janssens
You need to first make a trivial version where particle are a point class with
class particle
Vector3 speed
Vector3 position
double mass

then with two loop on the particle vector you can compute gravitationnal force and then integrate acceleration to move the particle.
For the visualisation OpenGl is well defined. After this you must use an Octree to accelerate the computation time. It's more complex but faster.
Octree can be parallelised on multiple CPU by using OpenMP or on multiple computer by an handcoded parralel computing system.
It need time, this is the only secret.
 

Similar threads

  • · Replies 19 ·
Replies
19
Views
4K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K