3.4 N-body Simulation Introduction to Programming in Java: An Interdisciplinary Approach · Robert Sedgewick and Kevin Wayne · Copyright.

Slides:



Advertisements
Similar presentations
AP Physics C Mechanics Review.
Advertisements

UNIT 6 (end of mechanics) Universal Gravitation & SHM
UNIT 6 (end of mechanics) Universal Gravitation & SHM.
Chapter 13 Gravitation PhysicsI 2048.
Review Chap. 12 Gravitation
Newton’s Law of Universal Gravitation.  Any two objects exert a gravitational force of attraction on each other. The magnitude of the force is proportional.
© copyright 2013-William A. Goddard III, all rights reservedCh120a-Goddard-L06 Ch121a Atomic Level Simulations of Materials and Molecules William A. Goddard.
Week 10 Dark Matter Reading: Dark Matter: 16.1, 16.5d (4 pages)
Ryuji Morishima (UCLA/JPL). N-body code: Gravity solver + Integrator Gravity solver must be fast and handle close encounters Special hardware (N 2 ):
Course Outline Introduction in algorithms and applications Parallel machines and architectures Overview of parallel machines, trends in top-500 Cluster.
Halliday/Resnick/Walker Fundamentals of Physics 8th edition
1 Lucifer’s Hammer Derek Mehlhorn William Pearl Adrienne Upah A Computer Simulation of Asteroid Trajectories Team 34 Albuquerque Academy.
Module on Computational Astrophysics Jim Stone Department of Astrophysical Sciences 125 Peyton Hall : ph :
Sect. 3.12: The Three Body Problem So far: We’ve done the 2 Body Problem. –Central forces only. –Eqtns of motion are integrable. Can write as integrals.
Angular Momentum (of a particle) O The angular momentum of a particle, about the reference point O, is defined as the vector product of the position, relative.
Physics 121 Newtonian Mechanics Lecture notes are posted on Instructor Karine Chesnel April 2, 2009.
Module on Computational Astrophysics Professor Jim Stone Department of Astrophysical Sciences and PACM.
Introduction Mechanics: deals with the responses of the bodies to the action of forces. Objectives: To give students an introduction to engineering mechanics.
Physics 202: Introduction to Astronomy – Lecture 4 Carsten Denker Physics Department Center for Solar–Terrestrial Research.
Physics 111: Elementary Mechanics – Lecture 12 Carsten Denker NJIT Physics Department Center for Solar–Terrestrial Research.
Module on Computational Astrophysics Jim Stone Department of Astrophysical Sciences 125 Peyton Hall : ph :
Simulations of The Three- Body Problem: Finding Chaos in the Cosmos Craig Huber and Leah Zimmerman San Francisco State University Mathematics 490 Professor.
CH 12: Gravitation. We have used the gravitational acceleration of an object to determine the weight of that object relative to the Earth. Where does.
Sect. 13.3: Kepler’s Laws & Planetary Motion. German astronomer (1571 – 1630) Spent most of his career tediously analyzing huge amounts of observational.
MA/CS 375 Fall MA/CS 375 Fall 2002 Lecture 13.
Spring Topic Outline for Physics 1 Spring 2011.
Gravity & orbits. Isaac Newton ( ) developed a mathematical model of Gravity which predicted the elliptical orbits proposed by Kepler Semi-major.
Newton’s Law of Universal Gravitation
Lecture 5: Gravity and Motion
Course Outline Introduction in algorithms and applications Parallel machines and architectures Overview of parallel machines, trends in top-500, clusters,
Gravity. Newton’s Law of Universal Gravitation Newton’s insight: The force accelerating an apple downward is the same force that keeps the Moon in its.
Class 5 : Binary stars and stellar masses The importance of binary stars The dynamics of a binary system Determining the masses of stars.
More on Kepler’s Laws. Can be shown that this also applies to an elliptical orbit with replacement of r with a, where a is the semimajor axis. K s is.
MA/CS 375 Fall MA/CS 375 Fall 2002 Lecture 12.
Introduction to Particle Simulations Daniel Playne.
CSCI-455/552 Introduction to High Performance Computing Lecture 11.5.
Proportionality between the velocity V and radius r
Uniform Circular Motion. What is uniform circular motion? Constant speed Circular path Must be an unbalanced force acting towards axis of rotation- think.
Gravitation. Gravitational Force the mutual force of attraction between particles of matter Newton’s Law of Universal Gravitation F g =G(m 1* m 2 /r 2.
Dynamics of Uniform Circular Motion Uniform Circular Motion Centripetal Acceleration Centripetal Force Satellites in Circular Orbits Vertical Circular.
Chapter 13 Gravitation Newton’s Law of Gravitation Here m 1 and m 2 are the masses of the particles, r is the distance between them, and G is the.
Copyright © 2010 Pearson Education, Inc. Lecture Outline Chapter 12 Physics, 4 th Edition James S. Walker.
Daily Science Pg.30 Write a formula for finding eccentricity. Assign each measurement a variable letter. If two focus points are 450 km away from one another.
Ch 8 : Conservation of Linear Momentum 1.Linear momentum and conservation 2.Kinetic Energy 3.Collision 1 dim inelastic and elastic nut for 2 dim only inellastic.
1 Two of Newton’s Law of Motions 1) In the absence of any forces applied, an object at rest will stay at rest, and a body moving at a constant velocity.
Questions From Reading Activity? Assessment Statements Gravitational Field, Potential and Energy Explain the concept of escape speed from a planet.
CompSci 100e2.1 1 N-Body Simulation l Applications to astrophysics.  Orbits of solar system bodies.  Stellar dynamics at the galactic center.  Stellar.
Gravitation and the Waltz of the Planets Chapter 4.
2006: Assoc. Prof. R. J. Reeves Gravitation 1.1 P113 Gravitation: Lecture 1 Background to Newton’s Gravitation Law Background to Newton’s Discovery –Copernicus,
Section Orbital Motion of Satellites and Kepler’s Laws
Newton’s Law of Universal Gravitation
Section 7-1 Circular Motion Acceleration can be produced by a change in magnitude of the velocity and/or by a change in ____________________ of the velocity.
4.2 Gravity and Kepler’s Solar System p Falling Objects The Moon in Free Fall Newton understood that the Moon was in free-fall around the Earth.
The Newtonian Synthesis Nicolaus Copernicus 1473 – 1543 Frame of Reference Tycho Brahe Accurate Data Johannes Kepler Emperical Laws.
1 The law of gravitation can be written in a vector notation (9.1) Although this law applies strictly to particles, it can be also used to real bodies.
Gravity and Motion. Kepler’s Theory of Planetary Motion 1. Paths are ellipses and sun at the focus 2. Planets move faster when closer 3. Relationship.
Setup distribution of N particles
Mass training of trainers General Physics 1
Chapter 12 Gravity.
Physics Vocabulary Words
Exam 2 Review 1.
Isaac Newton ( ) Newton’s Laws of Motion
Gravity and Motion.
Newton, Einstein, and Gravity
Setup distribution of N particles
Chapter 2 Astronomy.
Mechanics Gravitations MARLON FLORES SACEDON.
Introduction to Computer Science I.
Chapter 2 - Part 1 The two body problem
N-Body Gravitational Simulations
Presentation transcript:

3.4 N-body Simulation Introduction to Programming in Java: An Interdisciplinary Approach · Robert Sedgewick and Kevin Wayne · Copyright © 2008 · April 15, 2017 2:38 tt

N-Body Problem Goal. Determine the motion of N particles, moving under their mutual Newtonian gravitational forces. Ex. Planets orbit the sun.

N-Body: Applications Applications to astrophysics. Orbits of solar system bodies. Stellar dynamics at the galactic center. Stellar dynamics in a globular cluster. Stellar dynamics during the collision of two galaxies. Formation of structure in the universe. Dynamics of galaxies during cluster formation.

N-Body Problem Goal. Determine the motion of N particles, moving under their mutual Newtonian gravitational forces. Context. Newton formulated the physical principles in Principia. Newton's second law of motion Newton's law of universal gravitation The n-body problem was one of the most important fields of study in the 18th and 19th centuries, Kepler Bernoulli Newton Euler Lagrange Delaunay Poincaré

2-Body Problem 2 body problem. Can be solved analytically via Kepler's 3rd law. Bodies move around a common barycenter (center-of-mass) with elliptical orbits.

3-Body Problem 3-body problem. No solution possible in terms of elementary functions; moreover, orbits may not be stable or periodic! Consequence. Must resort to computational methods. Unstable and aperiodic orbits came as a great shock at the time. Poincare ended up inventing chaos theory as a result of study of 3-body problem!

N-Body Simulation N-body simulation. The ultimate object-oriented program: simulate the universe.

Body Data Type Body data type. Represent a particle. Vector notation. Represent position, velocity, and force using Vector. public class Body { private Vector r; // position private Vector v; // velocity private double mass; // mass instance variables

Moving a Body Moving a body. Assuming no other forces, body moves in straight line. r = r.plus(v.times(dt));

Moving a Body Moving a body. Given external force F, acceleration a = F/m. Use acceleration (assume fixed) to compute change in velocity. Use velocity to compute change in position. Vector a = f.times(1/mass); v = v.plus(a.times(dt)); r = r.plus(v.times(dt));

Force Between Two Bodies Newton's law of universal gravitation. F = G m1 m2 / r 2. Direction of force is line between two particles. double G = 6.67e-11; Vector delta = a.r.minus(b.r); double dist = delta.magnitude(); double F = (G * a.mass * b.mass) / (dist * dist); Vector force = delta.direction().times(F);

Body Data Type: Java Implementation public class Body { private Vector r; // position private Vector v; // velocity private double mass; // mass public Body(Vector r, Vector v, double mass) { this.r = r; this.v = v; this.mass = mass; } public void move(Vector f, double dt) { Vector a = f.times(1/mass); v = v.plus(a.times(dt)); r = r.plus(v.times(dt)); public Vector forceTo(Body that) { double G = 6.67e-11; Vector delta = this.r.minus(that.r); double dist = delta.magnitude(); double F = (G * this.mass * that.mass) / (dist * dist); return delta.direction().times(F); public void draw() { StdDraw.setPenRadius(0.025); StdDraw.point(r.cartesian(0), r.cartesian(1));

Force Between Two Bodies Newton's law of universal gravitation. F = G m1 m2 / r 2. Direction of force is line between two particles. double G = 6.67e-11; Vector delta = a.r.minus(b.r); double dist = delta.magnitude(); double F = (G * a.mass * b.mass) / (dist * dist); Vector force = delta.direction().times(F);

Universe Data Type Universe data type. Represent a universe of N particles. public static void main(String[] args) { Universe newton = new Universe(); double dt = Double.parseDouble(args[0]); while (true) { StdDraw.clear(); newton.increaseTime(dt); newton.draw(); StdDraw.show(10); } main simulation loop

Universe Data Type Universe data type. Represent a universe of N particles. public class Universe { private double radius; // radius of universe private int N // number of particles private Body[] orbs; // the bodies instance variables

Data-Driven Design File format. Constructor. public Universe() { N = StdIn.readInt(); radius = StdIn.readDouble(); StdDraw.setXscale(-radius, +radius); StdDraw.setYscale(-radius, +radius); // read in the N bodies orbs = new Body[N]; for (int i = 0; i < N; i++) { double rx = StdIn.readDouble(); double ry = StdIn.readDouble(); double vx = StdIn.readDouble(); double vy = StdIn.readDouble(); double mass = StdIn.readDouble(); double[] position = { rx, ry }; double[] velocity = { vx, vy }; Vector r = new Vector(position); Vector v = new Vector(velocity); orbs[i] = new Body(r, v, mass); }

Principle of Superposition Principle of superposition. Net gravitational force acting on a body is the sum of the individual forces. // compute the forces for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (i != j) { f[i] = f[i].plus(orbs[j].forceTo(orbs[i])); }

Universe Data Type: Java Implementation public class Universe { private final double radius; // radius of universe private final int N; // number of bodies private final Body[] orbs; // array of N bodies public Universe() { /* see previous slide */ } public void increaseTime(double dt) { Vector[] f = new Vector[N]; for (int i = 0; i < N; i++) f[i] = new Vector(new double[2]); for (int j = 0; j < N; j++) if (i != j) f[i] = f[i].plus(orbs[j].forceTo(orbs[i])); orbs[i].move(f[i], dt); } public void draw() { orbs[i].draw(); public static void main(String[] args) { /* see previous slide */ } create universe update the bodies draw the bodies simulate the universe

Odds and Ends Accuracy. How small to make dt? How to avoid floating-point inaccuracies from accumulating? Efficiency. Direct sum: takes time proportional to N2  not usable for large N. Appel / Barnes-Hut: takes time proportional to N log N time  can simulate large universes. 3D universe. Use a 3D vector (only drawing code changes!). Collisions. Model inelastic collisions. Use a softening parameter to avoid collisions.

Extra Slides

N-Body Simulation 1. Setup initial distribution of particles. Need accurate data and model of mass distribution. 2. Compute forces between particles. Direct sum: N2. Appel / Barnes-Hut" N log N. 3. Evolve particles using ODE solver. Leapfrog method balances efficiency and accuracy. Truncation error = O(dt^2). Symplectic. 4. Display and analyze results. e = softening parameter eliminates binary stars with r < e hard binaries can be important source of energy hard binary = very small separation

Solving the force problem with hardware. GRAPE-6. Special purpose hardware to compute force. The 6th generation of GRAPE (Gravity Pipe) Project Gravity calculation with 31 Gflops/chip 32 chips / board ⇒ 0.99 Tflops/board 64 boards of full system is installed in University of Tokyo ⇒ 63 Tflops On each board, all particle data are set onto SRAM memory, and each target particle data is injected into the pipeline, then acceleration data is calculated Gordon Bell Prize at SC2000, SC2001 (Prof. Makino, U. Tokyo) also nominated at SC2002 Jun Makino, U. Tokyo

Andromeda – 2 million light years away Do we really need to compute force from every star for distant objects? Andromeda – 2 million light years away

Solving the force problem with software -- tree codes Distance = 25 times size

Organize particles into a tree Organize particles into a tree. In Barnes-Hut algorithm, use a quadtree in 2D