Actual source code: test7f.F
1: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2: ! SLEPc - Scalable Library for Eigenvalue Problem Computations
3: ! Copyright (c) 2002-2011, 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 <finclude/petscsys.h>
34: #include <finclude/petscvec.h>
35: #include <finclude/petscmat.h>
36: #include <finclude/slepcsys.h>
37: #include <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)
81: i1 = 1
82: i2 = 2
83: i3 = 3
84: call MatGetOwnershipRange(A,Istart,Iend,ierr)
85: if (Istart .eq. 0) then
86: i = 0
87: col(1) = 0
88: col(2) = 1
89: value(1) = 2.0
90: value(2) = -1.0
91: call MatSetValues(A,i1,i,i2,col,value,INSERT_VALUES,ierr)
92: Istart = Istart+1
93: endif
94: if (Iend .eq. n) then
95: i = n-1
96: col(1) = n-2
97: col(2) = n-1
98: value(1) = -1.0
99: value(2) = 2.0
100: call MatSetValues(A,i1,i,i2,col,value,INSERT_VALUES,ierr)
101: Iend = Iend-1
102: endif
103: value(1) = -1.0
104: value(2) = 2.0
105: value(3) = -1.0
106: do i=Istart,Iend-1
107: col(1) = i-1
108: col(2) = i
109: col(3) = i+1
110: call MatSetValues(A,i1,i,i3,col,value,INSERT_VALUES,ierr)
111: enddo
113: call MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY,ierr)
114: call MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY,ierr)
116: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
117: ! Create the eigensolver and display info
118: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
120: ! ** Create eigensolver context
121: call EPSCreate(PETSC_COMM_WORLD,eps,ierr)
123: ! ** Set operators. In this case, it is a standard eigenvalue problem
124: call EPSSetOperators(eps,A,PETSC_NULL_OBJECT,ierr)
125: call EPSSetProblemType(eps,EPS_HEP,ierr)
127: ! ** Set solver parameters at runtime
128: call EPSSetFromOptions(eps,ierr)
130: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
131: ! Solve the eigensystem
132: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
134: call EPSSolve(eps,ierr)
135:
136: ! ** Optional: Get some information from the solver and display it
137: call EPSGetType(eps,tname,ierr)
138: if (rank .eq. 0) then
139: write(*,120) tname
140: endif
141: 120 format (' Solution method: ',A)
142: call EPSGetDimensions(eps,nev,PETSC_NULL_INTEGER, &
143: & PETSC_NULL_INTEGER,ierr)
144: if (rank .eq. 0) then
145: write(*,130) nev
146: endif
147: 130 format (' Number of requested eigenvalues:',I2)
149: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
150: ! Display solution and clean up
151: ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
153: call EPSPrintSolution(eps,PETSC_NULL_OBJECT,ierr)
154: call EPSDestroy(eps,ierr)
155: call MatDestroy(A,ierr)
157: call SlepcFinalize(ierr)
158: end