Date: 2015-09-03T15:05:06+00:00

Actual source code: test7f.F
slepc-3.6.1 2015-09-03
Report Typos and Errors

      1: !  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      2: !  SLEPc - Scalable Library for Eigenvalue Problem Computations
      3: !  Copyright (c) 2002-2015, Universitat Politecnica de Valencia, Spain
      4: !
      5: !  This file is part of SLEPc.
      6: !
      7: !  SLEPc is free software: you can redistribute it and/or modify it under  the
      8: !  terms of version 3 of the GNU Lesser General Public License as published by
      9: !  the Free Software Foundation.
     10: !
     11: !  SLEPc  is  distributed in the hope that it will be useful, but WITHOUT  ANY
     12: !  WARRANTY;  without even the implied warranty of MERCHANTABILITY or  FITNESS
     13: !  FOR  A  PARTICULAR PURPOSE. See the GNU Lesser General Public  License  for
     14: !  more details.
     15: !
     16: !  You  should have received a copy of the GNU Lesser General  Public  License
     17: !  along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
     18: !  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     19: !
     20: !  Program usage: mpirun -np n test7f [-help] [-n <n>] [all SLEPc options]
     21: !
     22: !  Description: Simple example that solves an eigensystem with the EPS object.
     23: !  Same problem as ex1f but with simplified output.
     24: !
     25: !  The command line options are:
     26: !    -n <n>, where <n> = number of grid points = matrix size
     27: !
     28: ! ----------------------------------------------------------------------
     29: !
     30:       program main
     31:       implicit none

     33: #include <petsc/finclude/petscsys.h>
     34: #include <petsc/finclude/petscvec.h>
     35: #include <petsc/finclude/petscmat.h>
     36: #include <slepc/finclude/slepcsys.h>
     37: #include <slepc/finclude/slepceps.h>

     39: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     40: !     Declarations
     41: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     42: !
     43: !  Variables:
     44: !     A     operator matrix
     45: !     eps   eigenproblem solver context

     47:       Mat            A
     48:       EPS            eps
     49:       EPSType        tname
     50:       PetscInt       n, i, Istart, Iend
     51:       PetscInt       nev
     52:       PetscInt       col(3)
     53:       PetscInt       i1,i2,i3
     54:       PetscMPIInt    rank
     55:       PetscErrorCode ierr
     56:       PetscBool      flg
     57:       PetscScalar    value(3)

     59: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     60: !     Beginning of program
     61: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

     63:       call SlepcInitialize(PETSC_NULL_CHARACTER,ierr)
     64:       call MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr)
     65:       n = 30
     66:       call PetscOptionsGetInt(PETSC_NULL_CHARACTER,'-n',n,flg,ierr)

     68:       if (rank .eq. 0) then
     69:         write(*,100) n
     70:       endif
     71:  100  format (/'1-D Laplacian Eigenproblem, n =',I3,' (Fortran)')

     73: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     74: !     Compute the operator matrix that defines the eigensystem, Ax=kx
     75: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

     77:       call MatCreate(PETSC_COMM_WORLD,A,ierr)
     78:       call MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,n,n,ierr)
     79:       call MatSetFromOptions(A,ierr)
     80:       call MatSetUp(A,ierr)

     82:       i1 = 1
     83:       i2 = 2
     84:       i3 = 3
     85:       call MatGetOwnershipRange(A,Istart,Iend,ierr)
     86:       if (Istart .eq. 0) then
     87:         i = 0
     88:         col(1) = 0
     89:         col(2) = 1
     90:         value(1) =  2.0
     91:         value(2) = -1.0
     92:         call MatSetValues(A,i1,i,i2,col,value,INSERT_VALUES,ierr)
     93:         Istart = Istart+1
     94:       endif
     95:       if (Iend .eq. n) then
     96:         i = n-1
     97:         col(1) = n-2
     98:         col(2) = n-1
     99:         value(1) = -1.0
    100:         value(2) =  2.0
    101:         call MatSetValues(A,i1,i,i2,col,value,INSERT_VALUES,ierr)
    102:         Iend = Iend-1
    103:       endif
    104:       value(1) = -1.0
    105:       value(2) =  2.0
    106:       value(3) = -1.0
    107:       do i=Istart,Iend-1
    108:         col(1) = i-1
    109:         col(2) = i
    110:         col(3) = i+1
    111:         call MatSetValues(A,i1,i,i3,col,value,INSERT_VALUES,ierr)
    112:       enddo

    114:       call MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY,ierr)
    115:       call MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY,ierr)

    117: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    118: !     Create the eigensolver and display info
    119: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    121: !     ** Create eigensolver context
    122:       call EPSCreate(PETSC_COMM_WORLD,eps,ierr)

    124: !     ** Set operators. In this case, it is a standard eigenvalue problem
    125:       call EPSSetOperators(eps,A,PETSC_NULL_OBJECT,ierr)
    126:       call EPSSetProblemType(eps,EPS_HEP,ierr)

    128: !     ** Set solver parameters at runtime
    129:       call EPSSetFromOptions(eps,ierr)

    131: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    132: !     Solve the eigensystem
    133: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    135:       call EPSSolve(eps,ierr)

    137: !     ** Optional: Get some information from the solver and display it
    138:       call EPSGetType(eps,tname,ierr)
    139:       if (rank .eq. 0) then
    140:         write(*,120) tname
    141:       endif
    142:  120  format (' Solution method: ',A)
    143:       call EPSGetDimensions(eps,nev,PETSC_NULL_INTEGER,                 &
    144:      &                      PETSC_NULL_INTEGER,ierr)
    145:       if (rank .eq. 0) then
    146:         write(*,130) nev
    147:       endif
    148:  130  format (' Number of requested eigenvalues:',I2)

    150: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    151: !     Display solution and clean up
    152: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    154:       call EPSErrorView(eps,EPS_ERROR_RELATIVE,PETSC_NULL_OBJECT,ierr)
    155:       call EPSDestroy(eps,ierr)
    156:       call MatDestroy(A,ierr)

    158:       call SlepcFinalize(ierr)
    159:       end