The Fast Multipole Method and other Fast Summation Techniques Gunnar Martinsson The University of Colorado at Boulder
(The factor of 1/2π is suppressed.) Problem definition: Consider the task of evaluation the sum N (1) u i = G(x i, x j ) q j, i = 1, 2,..., N, j=1 where {x i } N i=1 is a given set of points in a square Ω in the plane, where {q i } N i=1 is a given set of real numbers which we call charges, and where {u i } N i=1 is a sought set of real numbers which we call potentials. The kernel G is given by log(x y), when x y (2) G(x, y) = 0 when x = y. Recall: A point x R 2 is represented by the complex number x = x 1 + i x 2 C. Then the kernel in (2) is a complex representation of the fundamental solution to the Laplace equation in R 2 since log x y = Real ( log(x y) ).
Special case: Sources and targets are separate Charges q j at locations {y j } N j=1. Potentials u i at locations {x i } M i=1. u i = N q j log(x i y j ), j=1 i = 1, 2,..., M u i = u(x i ), i = 1, 2,..., M u(x) = N q j log(x y j ) j=1 Direct evaluation Cost is O(M N).
Special case: Sources and targets are separate Charges q j at locations {y j } N j=1. Potentials u i at locations {x i } M i=1. u i = N q j log(x i y j ), j=1 i = 1, 2,..., M u i = u(x i ), i = 1, 2,..., M u(x) = N q j log(x y j ) j=1 Multipole expansion: Since u is harmonic outside the magenta circle, we know that 1 u(x) = α 0 log(x c) + α p (x c) p, where α p = 1 N ( q j yj c) p. p p=1 j=1
Special case: Sources and targets are separate Charges q j at locations {y j } N j=1. Potentials u i at locations {x i } M i=1. u i = N q j log(x i y j ), j=1 i = 1, 2,..., M u i = u(x i ), i = 1, 2,..., M u(x) = N q j log(x y j ) j=1 Multipole expansion truncated to P + 1 terms: Since u is harmonic outside the magenta circle, we know that P 1 u(x) = α 0 log(x c) + α p (x c) p + E P, where α p = 1 N ( q j yj c) p. p p=1 j=1 ( r ) ( ) P ( ) P P 2a 2 The approximation error E P scales as E P = =. R a
Special case: Sources and targets are separate Charges q j at locations {y j } N j=1. Potentials u i at locations {x i } M i=1. u i = N q j log(x i y j ), j=1 i = 1, 2,..., M u i = u(x i ), i = 1, 2,..., M u(x) = N q j log(x y j ) j=1 Multipole expansion truncated to P + 1 terms costs: Evaluate α p = 1 N ( q j yj c) p for p = 0, 1,..., P cost is O(N P ). p j=1 Evaluate u i = α 0 log(x c) + P p=1 1 α p cost is O(M P ). (x c) p
We write the map in matrix form as A B C ε, or q C ˆq A 2222222 2 B where q = [q j ] N j=1 RN is the vector of sources u = [u i ] M i=1 CM is the vector of potentials ˆq = [ˆq p ] N p=0 CP +1 is the outgoing expansion (the multipole coefficients ) A C M N C C (P +1) N is the outgoing-from-sources map B C M (P +1) is the targets-from-outgoing map. u A ij = log(x i y j ) 1 p = 0 C pj = (1/p) (y j c) p p 0 log(x i c) p = 0 B ip = 1/(x i c) p p 0
Definition: Let Ω be a square with center c = (c 1, c 2 ) and side length 2a. Then we say that a point x R 2 is well-separated from Ω if max( x 1 c 1, x 2 c 2 ) a. y 1 6a 2a c y 2 y Ω x 1 x 2 x x Any point on or outside of the dashed square is well-separated from Ω. Consequently, the points x 2, x, and x are well-separated from Ω, but x 1 is not.
Single-level Barnes-Hut Suppose that we seek to evaluate all pairwise interactions between the N particles shown above. We suppose the particles are more or less evenly distributed for now.
Single-level Barnes-Hut Place a square grid of boxes on top of the computational box. Assume each box holds about N box particles (so there are about N/N box boxes).
Single-level Barnes-Hut How do you evaluate the potentials at the blue locations?
Single-level Barnes-Hut How do you evaluate the potentials at the blue locations? Directly evaluate interactions with the particles close by. For all long-distance interactions, use the out-going expansion!
Cost of the single-level Barnes-Hut algorithm: Let N box denote the number of particles in a box. For each particle, we need to do the following: Step 1: Evaluate the P outgoing moments: Step 2: Evaluate potentials from out-going expansions: Step : Evaluate potentials from close particles: P ((N/N box ) 9) P 9 N box Using that P is a smallish constant we find cost N 2 N box + N N box. Set N box N 1/2 to obtain: cost N 1.5. We re doing better than O(N 2 ) but still not great.
Notation single level Barnes-Hut: Partition the box Ω into smaller boxes and label them: 8 16 2 2 0 8 56 6 7 15 2 1 9 7 55 6 6 1 22 0 8 6 5 62 5 1 21 29 7 5 5 61 12 20 28 6 52 60 11 19 27 5 51 59 2 10 18 26 2 50 58 1 9 17 25 1 9 57 For a box τ, let L (nei) τ denote its neighbors, and L (far) τ denote the remaining boxes.
Notation single level Barnes-Hut: Partition the box Ω into smaller boxes and label them: 8 16 2 2 0 8 56 6 7 15 2 1 9 7 55 6 6 1 22 0 8 6 5 62 5 1 21 29 7 5 5 61 12 20 28 6 52 60 11 19 27 5 51 59 2 10 18 26 2 50 58 1 9 17 25 1 9 57 For a box τ, let L (nei) τ denote its neighbors, and L (far) τ denote the remaining boxes. The box τ = 21 is marked with red.
Notation single level Barnes-Hut: Partition the box Ω into smaller boxes and label them: 8 16 2 2 0 8 56 6 7 15 2 1 9 7 55 6 6 1 22 0 8 6 5 62 5 1 21 29 7 5 5 61 12 20 28 6 52 60 11 19 27 5 51 59 2 10 18 26 2 50 58 1 9 17 25 1 9 57 For a box τ, let L (nei) τ denote its neighbors, and L (far) τ denote the remaining boxes. The box τ = 21 is marked with red. L (nei) 21 = {12, 1, 1, 20, 22, 28, 29, 0} are the blue boxes.
Notation single level Barnes-Hut: Partition the box Ω into smaller boxes and label them: 8 16 2 2 0 8 56 6 7 15 2 1 9 7 55 6 6 1 22 0 8 6 5 62 5 1 21 29 7 5 5 61 12 20 28 6 52 60 11 19 27 5 51 59 2 10 18 26 2 50 58 1 9 17 25 1 9 57 For a box τ, let L (nei) τ denote its neighbors, and L (far) τ denote the remaining boxes. The box τ = 21 is marked with red. L (nei) 21 = {12, 1, 1, 20, 22, 28, 29, 0} are the blue boxes. L (far) 21 = are the green boxes.
Let J τ denote an index vector marking which particles belong to τ: j J τ x j is in box τ. Set q τ = q(j τ ) the sources in τ ˆq τ C P +1 the outgoing expansion for τ (the multipole coefficients ) u τ = u(j τ ) the potentials in τ Then q τ A σ,τ u σ C τ ˆq τ Bσ,τ Recall: P is an integer parameter balancing cost versus accuracy: P large high accuracy and high cost
Single-level Barnes-Hut Compute the outgoing expansions on all boxes: loop over all boxes τ ˆq τ = C τ q(j τ ) end loop Evaluate the far field potentials. Each box τ aggregates the contributions from all well-separated boxes: u = 0 loop over all boxes τ loop over all σ L (far) τ (i.e. all σ that are well-separated from τ) u(j τ ) = u(j τ ) + B τ,σ ˆq σ end loop end loop Evaluate the near field interactions: loop over all leaf boxes τ end u(j τ ) = u(j τ ) + A(J τ, J τ ) q(j τ ) + σ L (nei) τ A(J τ, J σ ) q(j σ )
To get the asymptotic cost down further, we need a hierarchical tree structure on the computational domain: Level 0 Level 1 5 1 2 Level 2 Level 11 1 19 21 2 5 51 50 5 52 75 7 77 76 8 82 85 8 10 12 18 20 9 8 1 0 7 6 9 8 71 70 7 72 79 78 81 80 7 9 15 17 27 26 29 28 5 7 6 59 58 61 60 67 66 69 68 6 8 1 16 2 22 25 2 1 0 2 55 5 57 56 6 62 65 6
We are given N locations and seek the potential at each location.
How do you find the potential at the locations marked in blue?
Tessellate the remainder of the domain using as large boxes as you can, with the constraint that the target box has to be well-separated from every box that is used.
Then replace the original charges in each well-separated box by the corresponding multipole expansion. The work required to evaluate one potential is now O(log N).
Cost of the multi-level Barnes-Hut algorithm: Suppose there are L levels in the tree, and that there are about N box particles in each box so that L log (N/N box ). We let N box is a fixed number (say N box 200) so L log(n). Observation: On each level, there are at most 27 well-separated boxes. For each particle x i, we need to do the following: Step 1: Evaluate the P outgoing moments for the L boxes holding x i : Step 2: Evaluate potentials from out-going expansions: Step : Evaluate potentials from neighbors: L P 27 L P 9 N box Using that P is a smallish constant (say P = 20) we find This is not bad. cost N L N log(n).
Multi-level Barnes-Hut Compute the outgoing expansions on all boxes: loop over all boxes τ on all levels ˆq τ = C τ q(j τ ) end loop For each box τ tessellate Ω into a minimal collection of boxes from which τ is well-separated, and evaluate the far-field potential: u = 0 loop over all boxes τ loop over all σ L (BH) τ (i.e. all σ that are well-separated from τ) u(j τ ) = u(j τ ) + B τ,σ ˆq σ end loop end loop Evaluate the near field interactions: loop over all leaf boxes τ end u(j τ ) = u(j τ ) + A(J τ, J τ ) q(j τ ) + σ L (nei) τ A(J τ, J σ ) q(j σ )
In the Barnes-Hut method, there is a need to construct for each box τ, the list L (BH) τ which identifies a minimal tessellation of Ω into boxes from which τ is well-separated. Example: The box τ is marked with blue. L (BH) τ = {???}
How do you find the tessellation?
2 2 2 2 2 2 2 2 2 2 How do you find the tessellation? Hint: Consider which level each box belongs to.
2 2 2 2 2 2 2 2 2 2 Level Level Level 2
Definition: For a box τ, define its interaction list L (int) τ 1. σ and τ populate the same level of the tree. 2. σ and τ are well-separated.. The parents of σ and τ touch. as the set of all boxes σ such that:
Example: Consider box τ = 10. 10
Example: Consider box τ = 10. 10 The green boxes are the neighbors of τ s parents.
Example: Consider box τ = 10. 10 The green boxes are the children of the neighbors of τ s parents.
Example: Consider box τ = 10. 19 21 10 18 20 15 17 6 8 1 16 The green boxes are the children of the neighbors of τ s parents. Only some of them are well-separated from τ. We find: L (int) τ = {6, 8, 1, 15, 16, 17, 18, 19, 20, 21}
Example: Consider box τ = 0. 0
Example: Consider box τ = 0. 0 The green boxes are the neighbors of τ s parents.
Example: Consider box τ = 0. 0 The green boxes are the children of the neighbors of τ s parents.
Example: Consider box τ = 0. 5 51 5 2 50 52 9 0 8 7 26 28 6 The green boxes are the children of the neighbors of τ s parents. Only some of them are well-separated from τ. We find: L (int) τ = {26, 28,, 6, 7, 2,,, 5, 8, 9, 50, 51, 52, 5}
Example: Consider box τ = 161. 161
Example: Consider box τ = 161. 161 The green boxes are the neighbors of τ s parents.
Example: Consider box τ = 161. 161 The green boxes are the children of the neighbors of τ s parents.
Example: Consider box τ = 161. 155 157 16 165 187 189 15 156 188 151 15 161 185 150 152 18 107 109 115 117 19 11 106 108 11 116 18 10 The green boxes are the children of the neighbors of τ s parents. Only some of them are well-separated from τ. We find: L (int) τ = {106, 107, 108, 109, 11, 115, 116, 117, 18, 19, 10, 11, 18, 185, 187, 188, 189, 150, 151, 152, 15, 15, 155, 156, 157, 16, 165}
Now let L (anc) τ great-grand-parent, etc.). Then denote the list of all ancestors (parent, grand-parent, L (BH) τ = L (int) τ σ L (anc) τ L (int) σ
5 51 5 19 21 2 50 52 155 15 151 150 157 16 165 187 156 15 161 152 189 188 185 18 9 8 18 20 107 106 109 108 115 11 117 116 19 18 11 10 7 15 17 26 28 6 6 8 1 16
2 5 51 50 5 52 19 21 161 0 9 8 10 18 20 7 26 28 6 15 17 6 8 1 16 L (anc) 161 = {, 10, 0} L (BH) 161 = L (int) L (int) 10 L (int) 0 L (int) 161 = {6, 8, 1, 15, 16, 17, 18, 19, 20, 21, 26, 28,, 6, 7, 2,,, 5, 8, 9, 50, 51, 52, 5, 106, 107, 108, 109, 11, 115, 116, 117, 18, 19, 10, 11, 150, 151, 152, 15, 15, 155, 156, 157, 16, 165, 18, 185, 187, 188, 189}