Actual source code: test7f.F

slepc-3.8.0 2017-10-20
Report Typos and Errors
  1: !
  2: !  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3: !  SLEPc - Scalable Library for Eigenvalue Problem Computations
  4: !  Copyright (c) 2002-2017, Universitat Politecnica de Valencia, Spain
  5: !
  6: !  This file is part of SLEPc.
  7: !  SLEPc is distributed under a 2-clause BSD license (see LICENSE).
  8: !  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9: !
 10: !  Program usage: mpiexec -n <np> ./test7f [-help] [-n <n>] [all SLEPc options]
 11: !
 12: !  Description: Simple example that solves an eigensystem with the EPS object.
 13: !  Same problem as ex1f but with simplified output.
 14: !
 15: !  The command line options are:
 16: !    -n <n>, where <n> = number of grid points = matrix size
 17: !
 18: ! ----------------------------------------------------------------------
 19: !
 20:       program main
 21: #include <slepc/finclude/slepceps.h>
 22:       use slepceps
 23:       implicit none

 25: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 26: !     Declarations
 27: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 28: !
 29: !  Variables:
 30: !     A     operator matrix
 31: !     eps   eigenproblem solver context

 33:       Mat            A
 34:       EPS            eps
 35:       EPSType        tname
 36:       PetscInt       n, i, Istart, Iend
 37:       PetscInt       nev
 38:       PetscInt       col(3)
 39:       PetscInt       i1,i2,i3
 40:       PetscMPIInt    rank
 41:       PetscErrorCode ierr
 42:       PetscBool      flg
 43:       PetscScalar    value(3)

 45: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 46: !     Beginning of program
 47: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

 49:       call SlepcInitialize(PETSC_NULL_CHARACTER,ierr)
 50:       call MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr)
 51:       n = 30
 52:       call PetscOptionsGetInt(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER,  &
 53:      &                        '-n',n,flg,ierr)

 55:       if (rank .eq. 0) then
 56:         write(*,100) n
 57:       endif
 58:  100  format (/'1-D Laplacian Eigenproblem, n =',I3,' (Fortran)')

 60: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 61: !     Compute the operator matrix that defines the eigensystem, Ax=kx
 62: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

 64:       call MatCreate(PETSC_COMM_WORLD,A,ierr)
 65:       call MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,n,n,ierr)
 66:       call MatSetFromOptions(A,ierr)
 67:       call MatSetUp(A,ierr)

 69:       i1 = 1
 70:       i2 = 2
 71:       i3 = 3
 72:       call MatGetOwnershipRange(A,Istart,Iend,ierr)
 73:       if (Istart .eq. 0) then
 74:         i = 0
 75:         col(1) = 0
 76:         col(2) = 1
 77:         value(1) =  2.0
 78:         value(2) = -1.0
 79:         call MatSetValues(A,i1,i,i2,col,value,INSERT_VALUES,ierr)
 80:         Istart = Istart+1
 81:       endif
 82:       if (Iend .eq. n) then
 83:         i = n-1
 84:         col(1) = n-2
 85:         col(2) = n-1
 86:         value(1) = -1.0
 87:         value(2) =  2.0
 88:         call MatSetValues(A,i1,i,i2,col,value,INSERT_VALUES,ierr)
 89:         Iend = Iend-1
 90:       endif
 91:       value(1) = -1.0
 92:       value(2) =  2.0
 93:       value(3) = -1.0
 94:       do i=Istart,Iend-1
 95:         col(1) = i-1
 96:         col(2) = i
 97:         col(3) = i+1
 98:         call MatSetValues(A,i1,i,i3,col,value,INSERT_VALUES,ierr)
 99:       enddo

101:       call MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY,ierr)
102:       call MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY,ierr)

104: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
105: !     Create the eigensolver and display info
106: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

108: !     ** Create eigensolver context
109:       call EPSCreate(PETSC_COMM_WORLD,eps,ierr)

111: !     ** Set operators. In this case, it is a standard eigenvalue problem
112:       call EPSSetOperators(eps,A,PETSC_NULL_MAT,ierr)
113:       call EPSSetProblemType(eps,EPS_HEP,ierr)

115: !     ** Set solver parameters at runtime
116:       call EPSSetFromOptions(eps,ierr)

118: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
119: !     Solve the eigensystem
120: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

122:       call EPSSolve(eps,ierr)

124: !     ** Optional: Get some information from the solver and display it
125:       call EPSGetType(eps,tname,ierr)
126:       if (rank .eq. 0) then
127:         write(*,120) tname
128:       endif
129:  120  format (' Solution method: ',A)
130:       call EPSGetDimensions(eps,nev,PETSC_NULL_INTEGER,                 &
131:      &                      PETSC_NULL_INTEGER,ierr)
132:       if (rank .eq. 0) then
133:         write(*,130) nev
134:       endif
135:  130  format (' Number of requested eigenvalues:',I2)

137: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
138: !     Display solution and clean up
139: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

141:       call EPSErrorView(eps,EPS_ERROR_RELATIVE,PETSC_NULL_VIEWER,ierr)
142:       call EPSDestroy(eps,ierr)
143:       call MatDestroy(A,ierr)

145:       call SlepcFinalize(ierr)
146:       end