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

In summary, this person is new to programming and wants to start doing N-body simulations. They are unfamiliar with the language and options available to them. They suggest looking into Open Source Physics and using a library called PixelFlow. They provide a github link for more information.
  • #1
allazar
4
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
  • #2
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 QuantumQuest, Hesch and S.G. Janssens
  • #3
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 S.G. Janssens
  • #4
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.
 

1. What is C++ and why is it used for N-Body Simulations?

C++ is a high-level programming language that is commonly used for developing complex and efficient applications. It is often used for N-Body Simulations because it allows for low-level control over the computer's hardware, making it ideal for handling large amounts of data and complex calculations.

2. Do I need any prior programming experience to learn C++ for N-Body Simulations?

While prior programming experience can be helpful, it is not necessary to learn C++ for N-Body Simulations. However, a strong understanding of basic programming concepts like variables, loops, and functions will make the learning process easier.

3. What tools do I need to start learning C++ for N-Body Simulations?

You will need a compiler, which is a software that translates the C++ code into machine-readable language, and an integrated development environment (IDE), which is a software that provides a user-friendly interface for writing, debugging, and testing code. Popular options include Visual Studio, Eclipse, and Code::Blocks.

4. Are there any recommended resources for learning C++ for N-Body Simulations?

Yes, there are many resources available online for learning C++ for N-Body Simulations. Some popular ones include online courses, tutorials, and books. It is also helpful to join online communities or forums where you can ask questions and learn from others.

5. How can I apply C++ for N-Body Simulations in my research or work?

C++ for N-Body Simulations can be applied in various fields, such as astrophysics, molecular dynamics, and aerodynamics. It can be used to simulate and analyze the behavior of particles in a system, providing valuable insights and predictions that can be applied in research and real-life applications.

Similar threads

  • Programming and Computer Science
Replies
19
Views
2K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
9
Views
2K
  • Programming and Computer Science
Replies
15
Views
2K
  • Classical Physics
Replies
2
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
4
Views
1K
  • Special and General Relativity
Replies
4
Views
882
  • Programming and Computer Science
Replies
4
Views
4K
Back
Top