Blame | Compare with Previous | Last modification | View Log | RSS feed
! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -! SLEPc - Scalable Library for Eigenvalue Problem Computations! Copyright (c) 2002-2011, Universitat Politecnica de Valencia, Spain!! This file is part of SLEPc.!! SLEPc is free software: you can redistribute it and/or modify it under the! terms of version 3 of the GNU Lesser General Public License as published by! the Free Software Foundation.!! SLEPc is distributed in the hope that it will be useful, but WITHOUT ANY! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS! FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for! more details.!! You should have received a copy of the GNU Lesser General Public License! along with SLEPc. If not, see <http://www.gnu.org/licenses/>.! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -!! Program usage: mpirun -np n ex1f90 [-help] [-n <n>] [all SLEPc options]!! Description: Simple example that solves an eigensystem with the EPS object.! The standard symmetric eigenvalue problem to be solved corresponds to the! Laplacian operator in 1 dimension.!! The command line options are:! -n <n>, where <n> = number of grid points = matrix size!! ----------------------------------------------------------------------!program main#include <finclude/slepcepsdef.h>use slepcepsimplicit none! For usage without modules, uncomment the following lines and remove! the previous lines between 'program main' and 'implicit none'!!#include <finclude/petsc.h>!#include <finclude/slepc.h>! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -! Declarations! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -!! Variables:! A operator matrix! solver eigenproblem solver context#if defined(PETSC_USE_FORTRAN_DATATYPES)type(Mat) Atype(EPS) solver#elseMat AEPS solver#endifEPSType tnamePetscReal tolPetscInt n, i, Istart, Iend, one, two, threePetscInt nev, maxitPetscInt row(1), col(3)PetscMPIInt rankPetscErrorCode ierrPetscBool flgPetscScalar value(3)! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -! Beginning of program! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -one = 1two = 2three = 3call SlepcInitialize(PETSC_NULL_CHARACTER,ierr)call MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr)n = 30call PetscOptionsGetInt(PETSC_NULL_CHARACTER,'-n',n,flg,ierr)if (rank .eq. 0) thenwrite(*,100) nendif100 format (/'1-D Laplacian Eigenproblem, n =',I4,' (Fortran)')! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -! Compute the operator matrix that defines the eigensystem, Ax=kx! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -call MatCreate(PETSC_COMM_WORLD,A,ierr)call MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,n,n,ierr)call MatSetFromOptions(A,ierr)call MatGetOwnershipRange(A,Istart,Iend,ierr)if (Istart .eq. 0) thenrow(1) = 0col(1) = 0col(2) = 1value(1) = 2.0value(2) = -1.0call MatSetValues(A,one,row,two,col,value,INSERT_VALUES,ierr)Istart = Istart+1endifif (Iend .eq. n) thenrow(1) = n-1col(1) = n-2col(2) = n-1value(1) = -1.0value(2) = 2.0call MatSetValues(A,one,row,two,col,value,INSERT_VALUES,ierr)Iend = Iend-1endifvalue(1) = -1.0value(2) = 2.0value(3) = -1.0do i=Istart,Iend-1row(1) = icol(1) = i-1col(2) = icol(3) = i+1call MatSetValues(A,one,row,three,col,value,INSERT_VALUES,ierr)enddocall MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY,ierr)call MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY,ierr)! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -! Create the eigensolver and display info! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -! ** Create eigensolver contextcall EPSCreate(PETSC_COMM_WORLD,solver,ierr)! ** Set operators. In this case, it is a standard eigenvalue problemcall EPSSetOperators(solver,A,PETSC_NULL_OBJECT,ierr)call EPSSetProblemType(solver,EPS_HEP,ierr)! ** Set solver parameters at runtimecall EPSSetFromOptions(solver,ierr)! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -! Solve the eigensystem! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -call EPSSolve(solver,ierr)! ** Optional: Get some information from the solver and display itcall EPSGetType(solver,tname,ierr)if (rank .eq. 0) thenwrite(*,120) tnameendif120 format (' Solution method: ',A)call EPSGetDimensions(solver,nev,PETSC_NULL_INTEGER, && PETSC_NULL_INTEGER,ierr)if (rank .eq. 0) thenwrite(*,130) nevendif130 format (' Number of requested eigenvalues:',I4)call EPSGetTolerances(solver,tol,maxit,ierr)if (rank .eq. 0) thenwrite(*,140) tol, maxitendif140 format (' Stopping condition: tol=',1P,E10.4,', maxit=',I4)! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -! Display solution and clean up! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -call EPSPrintSolution(solver,PETSC_NULL_OBJECT,ierr)call EPSDestroy(solver,ierr)call MatDestroy(A,ierr)call SlepcFinalize(ierr)end