1! file: bratu2df90.f90
2! to build a Python module, use this:
3! $$ f2py -m bratu2df90 -c bratu2df90.f90
4
5subroutine bratu2d (m, n, alpha, x, f)
6  !f2py intent(hide) :: m = shape(x,0)
7  !f2py intent(hide) :: n = shape(x,1)
8  integer                          :: m, n
9  real(kind=8)                     :: alpha
10  real(kind=8), intent(in), target :: x(m,n)
11  real(kind=8), intent(inout)      :: f(m,n)
12  real(kind=8) :: hx, hy
13  real(kind=8), pointer, &
14       dimension(:,:) :: u, uN, uS, uE, uW
15  ! setup 5-points stencil
16  u  => x(2:m-1, 2:n-1) ! center
17  uN => x(2:m-1, 1:n-2) ! north
18  uS => x(2:m-1, 3:n  ) ! south
19  uW => x(1:m-2, 2:n-1) ! west
20  uE => x(3:m,   2:n-1) ! east
21  ! compute nonlinear function
22  hx = 1.0/(m-1) ! x grid spacing
23  hy = 1.0/(n-1) ! y grid spacing
24  f(:,:) = x
25  f(2:m-1, 2:n-1) =  &
26         (2*u - uE - uW) * (hy/hx) &
27       + (2*u - uN - uS) * (hx/hy) &
28       - alpha * exp(u)  * (hx*hy)
29end subroutine bratu2d
30