Upgrade to Pro — share decks privately, control downloads, hide ads and more …

OpenMG: A New Multigrid Implementation in Python

OpenMG: A New Multigrid Implementation in Python

In many large-scale computations, systems of equations arise in the form Au=b, where A is a linear operation to be performed on the unknown data u, producing the known right-hand side, b, which represents some constraint of known or assumed behavior of the system being modeled. Since such systems can be very large, solving them directly can be too slow. In contrast, a multigrid solver solves partially at full resolution, and then solves directly only at low resolution. This creates a correction vector, which is then interpolated to full resolution, where it corrects the partial solution. This project aims to create an open-source multigrid solver called OpenMG, written only in Python. The existing PyAMG multigrid implementation is a highly versatile, configurable, black-box solver, but is difficult to read and modify due to its C core. Our proposed OpenMG is a pure Python experimentation environment for testing multigrid concepts, not a production solver. By making the code simple and modular, we make the algorithmic details clear. We thereby create an opportunity for education and experimentation with the partial solver (Jacobi, Gauss Seidel, SOR, etc.), the restriction mechanism, the prolongation mechanism, and the direct solver, or the use of GPGPUs, multiple CPUs, MPI, or grid computing. The resulting solver is tested on an implicit pressure reservoir simulation problem with satisfactory results.

tsbertalan

July 18, 2012
Tweet

Other Decks in Research

Transcript

  1. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    OpenMG: A New Multigrid Implementation in Python Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama 18 July, 2012 Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  2. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Outline 1 Motivation: Real-Life Examples 2 Mathematical Formulation 3 Multigrid 4 Algebraic Multigrid 5 Frequency Domain Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  3. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Petroleum Engineering: pressure driven flow Cross-section of an oil deposit. Photo credit: NOAA, J.Bratton. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  4. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Mechanical Engineering: heat transfer Temperature across a 2D plate in a time-stepping simulation with a Dirichlet boundary condition. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  5. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Medical Imaging: anisotropic diffusion Diffusion Tensor Magnetic Resonance Imaging (DTMRI) uses the diffusion paths of magnetically active particles to map neural tracts in the brain. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  6. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Constituitive Equations Petroleum Engineering Darcy’s Law: −κ µ ∇P = q Mechanical Engineering Heat Equation: α∇2u = ∂u ∂t Medical Imaging Fick’s Law: ∇ · (D∇c) = ∂c ∂t Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  7. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    2D Domain: Temperature Profile A hot conductive square is surrounded by cold, well-mixed fluid. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  8. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    2D Domain: Grid Coordinates Divide the domain into a discrete grid. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  9. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    2D Domain: Interior The set of interior points is called Ω... Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  10. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    2D Domain: Boundary ... and the set of boundary points is called Γ. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  11. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    2D Domain: Boundary Condition The temperature on Γ is known to be that of the fluid. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  12. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    2D Domain: Natural Ordering The vector u contains all the unknown interior temperatures. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  13. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Discrete Equation: Heat Conduction ∇2u = 1 α ∂u ∂t (1) If there are no heat sources or sinks, the divergence of the temperature is zero, that is, 1 α ∂u ∂t ≡ 0. In this case, we get the Laplace equation: ∇2u = 0 (2) Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  14. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Laplace Equation ∇2u = 0 (3) ∇2 is the Laplacian operator: ∇2u = ∂2u ∂x2 + ∂2u ∂y2 This is in continuous form, but after discretization of the second partial derivatives, we get Au = b (4) So, somehow we have represented ∇2 as a matrix A, and included the boundary conditions in b. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  15. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Discrete Equation: Partial Derivatives · · ui+1,j · · ui,j−1 ui,j ui,j+1 · · ui−1,j · · · · · Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  16. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Discrete Equation: Partial Derivatives · · ui+1,j · · ui,j−1 ui,j ui,j+1 · · ui−1,j · · · · · ∂2u ∂x2 ≈ ui,j+1−ui,j h − ui,j −ui,j−1 h h = 1 h2 (ui,j−1 − 2ui,j + ui,j+1) Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  17. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Discrete Equation: Partial Derivatives · · ui+1,j · · ui,j−1 ui,j ui,j+1 · · ui−1,j · · · · · ∂2u ∂x2 ≈ ui,j+1−ui,j h − ui,j −ui,j−1 h h = 1 h2 (ui,j−1 − 2ui,j + ui,j+1) ∂2u ∂y2 ≈ ui+1,j −ui,j h − ui,j −ui−1,j h h = 1 h2 (ui−1,j − 2ui,j + ui+1,j) Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  18. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Discrete Equation: Partial Derivatives · · ui+1,j · · ui,j−1 ui,j ui,j+1 · · ui−1,j · · · · · ∂2u ∂x2 ≈ ui,j+1−ui,j h − ui,j −ui,j−1 h h = 1 h2 (ui,j−1 − 2ui,j + ui,j+1) ∂2u ∂y2 ≈ ui+1,j −ui,j h − ui,j −ui−1,j h h = 1 h2 (ui−1,j − 2ui,j + ui+1,j) ∂2u ∂x2 + ∂2u ∂y2 ≈ 1 h2 (1ui−1,j + 1ui,j−1 − 4ui,j + 1ui,j+1 + 1ui+1,j) Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  19. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Discrete Equation: Matrix Form The entire matrix equation Au = b then looks like this:                    −4 1 1 1 −4 1 1 1 −4 1 1 1 1 -4 1 1 1 1 −4 1 1 ... ... ... ... ... 1 1 −4 1 1 1 1 −4 1 1 1 −4 1 1 1 −4                    ·                      u1 u2 · · · u15 u16                      =                      b1 b2 · · · b15 b16                      We need to solve for u, the vector of all interior temperatures. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  20. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Numerical Methods Direct (Gaussian elimination) Advantages: Accurate, finite number of steps. Disadvantages: Slow, not scalable to large problems. Iterative (Gauss-Seidel, Jacobi, SOR, etc.) Advantages: Scalable. Disadvantages: Does not always converge. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  21. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Multigrid: Given For a Laplace problem, start knowing only the boundary points. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  22. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Multigrid: Iterative Approximation Find uapprox via quick iterative solver. (We now need a correction v s.t. uapprox + v = u.) Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  23. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Multigrid: Coarse Points Define a coarse set, with only 1/4th the points of the full domain. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  24. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Multigrid: Coarse Correction Solve for vcoarse via accurate direct solver at the coarse resolution. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  25. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Multigrid: Interpolation to vfine Interpolate vcoarse to vfine. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  26. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Multigrid: Interpolation to vfine Interpolate vcoarse to vfine. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  27. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Multigrid: Interpolation to vfine Interpolate vcoarse to vfine. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  28. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Multigrid: Correction uapprox + vfine = u + = Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  29. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Multigrid: Solution The full-domain solution is the combination of Ω and Γ points. + = Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  30. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Multigrid: “Multi” This is a two-grid pattern, with only N/4 coarse points for the direct solver. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  31. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Multigrid: “Multi” This is a two-grid pattern, with only N/4 coarse points for the direct solver. However, we can also extend to a three-grid pattern, with N/16 points in the coarsest set. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  32. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Multigrid: “Multi” This is a two-grid pattern, with only N/4 coarse points for the direct solver. However, we can also extend to a three-grid pattern, with N/16 points in the coarsest set. By allowing the multigrid cycle function to call itself, recursively, we can extend to arbitrary N-grids. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  33. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Residual Equation The correction is defined by its action on the approximation: uapprox + v = u (5) From this we define the residual using the original right-hand-side: A(uapprox + v) = Au = b (6) Av = b − Auapprox = r (7) Equation 7 is the problem to be solved on the coarse grid. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  34. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Restriction Operators To make the residual equation easier to solve than the orginal problem, we define a restriction operator R that shrinks both the residual and the coefficient matrix. R can be any matrix of the right dimensions, but the choice of R should have a strong influence on the overall convergence rate. rH = R rh AH = R Ah RT Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  35. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Coarsening Methods Ruge-Steuben coarsening uses information present in the A to make R – only A and b must be supplied from the user. OpenMG currently uses a simpler geometric pattern of 2-, 4-, or 8-point averages to get the coarse grids. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  36. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Usefulness of Coarse Solution Can the coarse-resolution correction capture fine details? Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  37. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Usefulness of Coarse Solution Can the coarse-resolution correction capture fine details? It doesn’t have to! Gauss-Siedel solver smooths out fine error. All that’s left is the coarse components of the solution. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  38. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    GS Long-term Behavior For us, GS was only useful for the first (few) iteration(s). Achieving low error with GS alone takes dozens of hours. 2-grid with 1 GS iteration reduces error at a steady logarithmic rate. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  39. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Can more pre-smoothing help? Fedorenko: coarse grid corrections to an iterative solver. More pre-smoothing gives fewer v-cycles, but overall more time. More drastic coarsening would need more pre-iterations, but less coarse solution time. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  40. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    Direct vs GS vs Multigrid Define convergence as something GS can achieve in reasonable time. OpenMG is then faster than both the direct solver and the GS solver. This advantage grows as the number of unknowns increases. Production multigrid implementations are much, much faster. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  41. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    3D Problem - Pressure Solution Grey outer cylinder is isosurface of pressures at 23.2% of the range between max and min values. Innermost blue isosurface is 1 v-cycle. More v-cycles bring the solution closer to the direct solution. Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python
  42. Motivation: Real-Life Examples Mathematical Formulation Multigrid Algebraic Multigrid Frequency Domain

    OpenMG Repository http://github.com/tsbertalan/openmg Tom S Bertalan, Akand W Islam, Roger B Sidje, and Eric S Carlson The University of Alabama OpenMG: A New Multigrid Implementation in Python