Subversion Repositories slepc-dev

Compare Revisions

Ignore whitespace Rev 2743 → Rev 2744

/trunk/src/eps/examples/tests/output/test12_1.out New file
0,0 → 1,28
eps type krylovschur
 
Diagonal Eigenproblem, n=30
 
All requested eigenvalues computed up to the required tolerance:
30.00000, 29.00000, 28.00000, 27.00000
 
eps type arnoldi
 
Diagonal Eigenproblem, n=30
 
All requested eigenvalues computed up to the required tolerance:
30.00000, 29.00000, 28.00000, 27.00000
 
eps type gd
 
Diagonal Eigenproblem, n=30
 
All requested eigenvalues computed up to the required tolerance:
30.00000, 29.00000, 28.00000, 27.00000
 
eps type jd
 
Diagonal Eigenproblem, n=30
 
All requested eigenvalues computed up to the required tolerance:
30.00000, 29.00000, 28.00000, 27.00000
 
/trunk/src/eps/examples/tests/test11.c
41,6 → 41,7
Vec v0; /* initial vector */
Mat A; /* operator matrix */
EPS eps; /* eigenproblem solver context */
ST st; /* spectral transformation associated */
const EPSType type;
PetscReal tol=1000*PETSC_MACHINE_EPSILON;
PetscScalar target=0.5;
88,6 → 89,12
ierr = EPSSetEigenvalueComparison(eps,MyEigenSort,&target);CHKERRQ(ierr);
 
/*
Set the preconditioner based on A - target * I
*/
ierr = EPSGetST(eps,&st);CHKERRQ(ierr);
ierr = STSetShift(st,target);CHKERRQ(ierr);
 
/*
Set solver parameters at runtime
*/
ierr = EPSSetFromOptions(eps);CHKERRQ(ierr);
/trunk/src/eps/examples/tests/test12.c New file
0,0 → 1,107
/*
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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/>.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
 
static char help[] = "Diagonal eigenproblem.\n\n"
"The command line options are:\n"
" -n <n>, where <n> = number of grid subdivisions = matrix dimension.\n"
" -seed <s>, where <s> = seed for random number generation.\n\n";
 
#include <slepceps.h>
 
#undef __FUNCT__
#define __FUNCT__ "MyPCApply"
PetscErrorCode MyPCApply(PC pc,Vec x,Vec y)
{
PetscErrorCode ierr;
PetscFunctionBegin;
ierr = VecCopy(x,y);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
 
#undef __FUNCT__
#define __FUNCT__ "main"
int main(int argc,char **argv)
{
Mat A; /* problem matrix */
EPS eps; /* eigenproblem solver context */
Vec v0; /* initial vector */
PetscRandom rand;
PetscReal tol=1000*PETSC_MACHINE_EPSILON;
PetscInt n=30,i,Istart,Iend,seed=0x12345678;
PetscErrorCode ierr;
ST st;
KSP ksp;
PC pc;
 
SlepcInitialize(&argc,&argv,(char*)0,help);
 
ierr = PetscOptionsGetInt(PETSC_NULL,"-n",&n,PETSC_NULL);CHKERRQ(ierr);
ierr = PetscPrintf(PETSC_COMM_WORLD,"\nDiagonal Eigenproblem, n=%d\n\n",n);CHKERRQ(ierr);
 
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 = MatGetOwnershipRange(A,&Istart,&Iend);CHKERRQ(ierr);
for (i=Istart;i<Iend;i++) {
ierr = MatSetValue(A,i,i,i+1,INSERT_VALUES);CHKERRQ(ierr);
}
ierr = MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
ierr = MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
 
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Solve the eigensystem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
ierr = EPSCreate(PETSC_COMM_WORLD,&eps);CHKERRQ(ierr);
ierr = EPSSetOperators(eps,A,PETSC_NULL);CHKERRQ(ierr);
ierr = EPSSetProblemType(eps,EPS_HEP);CHKERRQ(ierr);
ierr = EPSSetTolerances(eps,tol,PETSC_DECIDE);CHKERRQ(ierr);
ierr = EPSSetFromOptions(eps);CHKERRQ(ierr);
ierr = EPSGetST(eps,&st);CHKERRQ(ierr);
ierr = STGetKSP(st,&ksp);CHKERRQ(ierr);
ierr = KSPGetPC(ksp,&pc);CHKERRQ(ierr);
ierr = PCSetType(pc,PCSHELL);CHKERRQ(ierr);
ierr = PCShellSetApply(pc,MyPCApply);CHKERRQ(ierr);
ierr = STPrecondSetMatForPC(st,A);CHKERRQ(ierr);
 
/* set random initial vector */
ierr = MatGetVecs(A,&v0,PETSC_NULL);CHKERRQ(ierr);
ierr = PetscRandomCreate(PETSC_COMM_WORLD,&rand);CHKERRQ(ierr);
ierr = PetscRandomSetFromOptions(rand);CHKERRQ(ierr);
ierr = PetscOptionsGetInt(PETSC_NULL,"-seed",&seed,PETSC_NULL);CHKERRQ(ierr);
ierr = PetscRandomSetSeed(rand,seed);CHKERRQ(ierr);
ierr = PetscRandomSeed(rand);CHKERRQ(ierr);
ierr = VecSetRandom(v0,rand);CHKERRQ(ierr);
ierr = EPSSetInitialSpace(eps,1,&v0);CHKERRQ(ierr);
/* call the solver */
ierr = EPSSolve(eps);CHKERRQ(ierr);
 
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Display solution and clean up
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
ierr = EPSPrintSolution(eps,PETSC_NULL);CHKERRQ(ierr);
ierr = EPSDestroy(&eps);CHKERRQ(ierr);
ierr = MatDestroy(&A);CHKERRQ(ierr);
ierr = VecDestroy(&v0);CHKERRQ(ierr);
ierr = PetscRandomDestroy(&rand);CHKERRQ(ierr);
ierr = SlepcFinalize();CHKERRQ(ierr);
return 0;
}
/trunk/src/eps/examples/tests/makefile
39,7 → 39,8
test8.PETSc runtest8_1 test8.rm \
test9.PETSc runtest9_1 test9.rm \
test10.PETSc runtest10_1 test10.rm \
test11.PETSc runtest11_1 test11.rm
test11.PETSc runtest11_1 test11.rm \
test12.PETSc runtest12_1 test12.rm
TESTEXAMPLES_FORTRAN = test7f.PETSc runtest7f_1 test7f.rm
TESTEXAMPLES_BLOPEX = test5.PETSc runtest5_blopex test5.rm
 
89,6 → 90,10
-${CLINKER} -o test11 test11.o ${SLEPC_LIB}
${RM} test11.o
 
test12: test12.o chkopts
-${CLINKER} -o test12 test12.o ${SLEPC_LIB}
${RM} test12.o
 
#------------------------------------------------------------------------------------
EPSALL = krylovschur arnoldi lanczos gd jd
EPSNS = krylovschur arnoldi gd jd
251,7 → 256,15
-@test=test11_1; \
for eps in ${EPSNS}; do \
echo "eps type $$eps"; \
if [ $$eps = krylovschur -o $$eps = arnoldi ]; then EXTRA="-st_shift 0.5 -st_type sinvert"; else EXTRA=""; fi; \
if [ $$eps = krylovschur -o $$eps = arnoldi ]; then EXTRA="-st_type sinvert"; else EXTRA=""; fi; \
${MPIEXEC} -np 1 ./test11 -eps_type $$eps -eps_nev 4 -eps_terse $$EXTRA 2>&1; \
done > $${test}.tmp;\
${TESTCODE}
 
runtest12_1:
-@test=test12_1; \
for eps in ${EPSNS}; do \
echo "eps type $$eps"; \
${MPIEXEC} -np 1 ./test12 -eps_type $$eps -eps_nev 4 -eps_terse 2>&1; \
done > $${test}.tmp; \
${TESTCODE}