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

Click For Summary

Discussion Overview

The discussion centers around getting started with C++ programming for N-body simulations, exploring various approaches, resources, and programming languages suitable for this task. Participants share their experiences and suggest tools and methods for numerical solving and visualization in the context of simulations.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant expresses uncertainty about how to begin programming in C++ for N-body simulations, mentioning their background in Python and numerical computations.
  • Another participant questions the choice of C/C++ over other languages like Java or Python, suggesting that speed or class requirements might be factors.
  • Suggestions are made to explore Open Source Physics, which provides Java classes for simulations, including ODE solvers and graphical plotting tools.
  • Alternatives such as using Python with Anaconda for numerical libraries or considering Julia as a MATLAB-like option are proposed.
  • Processing is recommended for its graphical capabilities, with references to libraries like PixelFlow for particle systems.
  • A more technical approach is suggested, starting with a simple particle class and using loops to compute gravitational forces, followed by visualization with OpenGL and optimization using an Octree structure.
  • Discussion includes the potential for parallelization using OpenMP or custom parallel computing systems, emphasizing the complexity and time required for these implementations.

Areas of Agreement / Disagreement

Participants present multiple competing views on the best programming language and approach for N-body simulations, with no consensus reached on a single method or tool.

Contextual Notes

Participants mention various programming languages and libraries, but there are no settled assumptions about the best practices or methodologies for implementing N-body simulations. The discussion reflects a range of experiences and suggestions without definitive conclusions.

Who May Find This Useful

Individuals interested in computational physics, programming for simulations, or those transitioning from Python to C++ for numerical applications may find this discussion relevant.

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
3K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K