-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuebung2.cpp
More file actions
39 lines (35 loc) · 982 Bytes
/
uebung2.cpp
File metadata and controls
39 lines (35 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include <time.h>
#include <omp.h>
#include <stdlib.h>
#include <math.h>
Vec v;
VecCreate(MPI Comm comm,Vec *v);
VecSetSizes(Vec v, PetscInt m, PetscInt M);
VecSetFromOptions(Vec v);
VecSet(Vec x,PetscScalar value);
VecSetValues(Vec x,PetscInt n,PetscInt *indices,PetscScalar
*values,INSERT VALUES);
VecAssemblyBegin(Vec x);
VecAssemblyEnd(Vec x);
VecView(Vec x,PetscViewer v);
VecDuplicate(Vec old,Vec *new);
VecDot(Vec x,Vec y,PetscScalar *dot);
Mat A;
EPS eps; /* eigensolver context */
Mat A; /* matrix of Ax=kx */
Vec xr, xi; /* eigenvector, x */
PetscScalar kr, ki; /* eigenvalue, k */
PetscInt j, nconv;
PetscReal error;
EPSCreate( PETSC_COMM_WORLD, &eps );
EPSSetOperators( eps, A, NULL );
EPSSetProblemType( eps, EPS_NHEP );
EPSSetFromOptions( eps );
EPSSolve( eps );
EPSGetConverged( eps, &nconv );
for (j=0; j<nconv; j++) {
EPSGetEigenpair( eps, j, &kr, &ki, xr, xi );
EPSComputeError( eps, j, EPS_ERROR_RELATIVE, &error );
}
EPSDestroy( &eps );