Question: use pipeline program to solve the N-body problem. JAVA code. N-body problem as following Suppose we are given a huge collection of astronomical bodies, such
Suppose we are given a huge collection of astronomical bodies, such as the stars clouds of dust, and dark matter in a galaxy. The problem is to simulate the evolu tion of the galaxy. Each body has a mass and an initial position and velocity. Gravity causes the bodies to accelerate and to move. The motion of an n-body system is simu- lated by stepping through discrete instants of time. At each time step, we calcu- late the forces on every body and then update their velocities and positions. A simulation of the gravitational n-body problem thus has the following structure: initialize bodies: for time start to finish by Dr] calculate forces move bodies The value of Dr (delta time) is the length of a time step. From Newtonian physics, the magnitude of the gravitational force between two bodies i and j is G m, m The m's are the masses of the two bodies, and r is the distance between them. Gravity is an extremely weak force, so the value of the gravitational constant G is the very small number 6.67.10-1 For simplicity, we will assume the bodies are all on the same spatial plane, and hence that we have only a two-dimensional problem. Let the positions of two bodies be (p, x, p,"y) and (p, x, p, y). Then the Euclidean distance between them is given by If two bodies come close to each other (a near collision), then r will be very small. This will lead to numerical instability in calculating forces, but we ignore the problem here The direction of the force on body i exerted by body j is given by a unit vec- tor that points from i to j. The direction of the force on body j due to body i is given by a unit vector that points in the opposite direction. Thus, the magnitudes of the forces of each body on the other are the same, but the directions are oppo- site. The total force on a body is the sum of the forces exerted by every other body. (Vector sums order.) are commutative, so the force vectors can be added in any
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
