File: bratu2df90.f90

package info (click to toggle)
petsc4py 3.22.4-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,396 kB
  • sloc: python: 12,130; ansic: 1,699; makefile: 342; f90: 313; sh: 14
file content (29 lines) | stat: -rw-r--r-- 946 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
! file: bratu2df90.f90
! to build a Python module, use this:
! $$ f2py -m bratu2df90 -c bratu2df90.f90

subroutine bratu2d (m, n, alpha, x, f)
  !f2py intent(hide) :: m = shape(x,0)
  !f2py intent(hide) :: n = shape(x,1)
  integer                          :: m, n
  real(kind=8)                     :: alpha
  real(kind=8), intent(in), target :: x(m,n)
  real(kind=8), intent(inout)      :: f(m,n)
  real(kind=8) :: hx, hy
  real(kind=8), pointer, &
       dimension(:,:) :: u, uN, uS, uE, uW
  ! setup 5-points stencil
  u  => x(2:m-1, 2:n-1) ! center
  uN => x(2:m-1, 1:n-2) ! north
  uS => x(2:m-1, 3:n  ) ! south
  uW => x(1:m-2, 2:n-1) ! west
  uE => x(3:m,   2:n-1) ! east
  ! compute nonlinear function
  hx = 1.0/(m-1) ! x grid spacing
  hy = 1.0/(n-1) ! y grid spacing
  f(:,:) = x
  f(2:m-1, 2:n-1) =  &
         (2*u - uE - uW) * (hy/hx) &
       + (2*u - uN - uS) * (hx/hy) &
       - alpha * exp(u)  * (hx*hy)
end subroutine bratu2d