/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SLEPc - Scalable Library for Eigenvalue Problem Computations Copyright (c) 2002-2016, 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 . - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ static char help[] = "Generalized Symmetric eigenproblem.\n\n" "The problem is Ax = lambda Bx, with:\n" " A = Laplacian operator in 2-D\n" " B = diagonal matrix\n\n" "The command line options are:\n" " -n , where = number of grid subdivisions in x dimension.\n" " -m , where = number of grid subdivisions in y dimension.\n\n"; #include #undef __FUNCT__ #define __FUNCT__ "main" int main(int argc,char **argv) { Mat A,B; /* matrices */ EPS eps; /* eigenproblem solver context */ ST st; /* spectral transformation context */ Vec x,b; KSP ksp; PC pc; PetscInt N,n=10,m,Istart,Iend,II,i,j; PetscReal norm; PetscBool flag,terse; PetscErrorCode ierr; PetscBool destroy, empty; ierr = SlepcInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr; ierr = PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);CHKERRQ(ierr); ierr = PetscOptionsGetInt(NULL,NULL,"-m",&m,&flag);CHKERRQ(ierr); if (!flag) m=n; N = n*m; ierr = PetscOptionsHasName(NULL,NULL,"-terse",&terse);CHKERRQ(ierr); ierr = PetscPrintf(PETSC_COMM_WORLD,"\nGeneralized Symmetric Eigenproblem, N=%D (%Dx%D grid)\n\n",N,n,m);CHKERRQ(ierr); /// Flags dealing with optional destruction of EPS object PetscOptionsHasName(NULL,NULL,"-destroy_eps",&destroy); PetscOptionsHasName(NULL,NULL,"-empty_ksp",&empty); /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Compute the matrices that define the eigensystem, Ax=kBx - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ ierr = MatCreate(PETSC_COMM_WORLD,&A);CHKERRQ(ierr); ierr = MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,N,N);CHKERRQ(ierr); ierr = MatSetFromOptions(A);CHKERRQ(ierr); ierr = MatSetUp(A);CHKERRQ(ierr); ierr = MatCreate(PETSC_COMM_WORLD,&B);CHKERRQ(ierr); ierr = MatSetSizes(B,PETSC_DECIDE,PETSC_DECIDE,N,N);CHKERRQ(ierr); ierr = MatSetFromOptions(B);CHKERRQ(ierr); ierr = MatSetUp(B);CHKERRQ(ierr); ierr = MatGetOwnershipRange(A,&Istart,&Iend);CHKERRQ(ierr); for (II=Istart;II0) { ierr = MatSetValue(A,II,II-n,-1.0,INSERT_VALUES);CHKERRQ(ierr); } if (i0) { ierr = MatSetValue(A,II,II-1,-1.0,INSERT_VALUES);CHKERRQ(ierr); } if (j