18.2-petsc-example

# 18.2-petsc-example - Introduction Example problem Code...

This preview shows pages 1–9. Sign up to view the full content.

Introduction Example problem Code implementation Learn more An example to demonstrate how to use PETSc (only very basic usage) Wenjun Deng January 2010

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Introduction Example problem Code implementation Learn more Introduction PETSc is a very powerful toolbox for manipulating linear algebraic objects (vectors, matrixes, etc.) using parallel computing. PETSc wraps the parallel operations (MPI) very well, so the programmer can ALMOST only focus on the mathematical objects. For example, you can create a matrix A and a vector b and tell PETSc to solve the linear equation Au = b , with ALMOST no need to care about how A and b are stored among nodes and how to parallelize the solving algorithm. ALMOST: when it comes to eﬃciency, you want to care a little about the parallel structure and algorithm.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Introduction Example problem Code implementation Learn more Example problem 2D Poisson’s equation -∇ 2 f ( x,y ) = sin( πx ) sin( πy ) in a square domain 0 x 1, 0 y 1. Boundary conditions: f (0 ,y ) = f (1 ,y ) = f ( x, 0) = f ( x, 1) = 0 Not hard to guess the analytic solution: f ( x,y ) = 1 2 π 2 sin( πx ) sin( πy )
Introduction Example problem Code implementation Learn more Use ﬁnite diﬀerence method to solve the problem Function f ( x,y ) can be discretized as f i,j and written as a vector: u = ( f 0 , 0 ,f 0 , 1 ,f 0 , 2 ··· ,f 0 ,n - 1 ,f 1 , 0 ,f 1 , 1 , ··· ,f n - 1 ,n - 1 ) T Similarly, h 2 sin( πx ) sin( πy ) can be discretized and written as a vector b . ( h is the grid size) Five-point Laplacian approximation: ( -∇ 2 f ) i,j 4 f i,j - f i - 1 ,j - f i +1 ,j - f i,j - 1 - f i,j +1 h 2 h 2 ( -∇ 2 f ) can be written as u multiplied by a matrix A , then the Poisson’s equation becomes a set of linear equations: Au = b

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document