Actual source code: shift.c
1: /*
2: Shift spectral transformation, applies (A + sigma I) as operator, or
3: inv(B)(A + sigma B) for generalized problems
4: */
5: #include src/st/stimpl.h
9: int STApply_Shift(ST st,Vec x,Vec y)
10: {
11: int ierr;
12: Vec w;
15: if (st->B) {
16: /* generalized eigenproblem: y = (B^-1 A + sI) x */
17: w = (Vec) st->data;
18: MatMult(st->A,x,w);
19: STAssociatedKSPSolve(st,w,y);
20: }
21: else {
22: /* standard eigenproblem: y = (A + sI) x */
23: MatMult(st->A,x,y);
24: }
25: if (st->sigma != 0.0) {
26: VecAXPY(&st->sigma,x,y);
27: }
28: return(0);
29: }
33: int STBackTransform_Shift(ST st,PetscScalar *eigr,PetscScalar *eigi)
34: {
36: if (eigr) *eigr -= st->sigma;
37: return(0);
38: }
42: static int STSetUp_Shift(ST st)
43: {
44: int ierr;
45: Vec w;
48: if (st->ksp) {
49: VecDuplicate(st->vec,&w);
50: st->data = (void *) w;
51: KSPSetRhs(st->ksp,st->vec);
52: KSPSetUp(st->ksp);
53: }
54: return(0);
55: }
59: static int STDestroy_Shift(ST st)
60: {
61: int ierr;
62: Vec w;
65: if (st->data) {
66: w = (Vec) st->data;
67: VecDestroy(w);
68: }
69: return(0);
70: }
72: EXTERN_C_BEGIN
75: int STCreate_Shift(ST st)
76: {
77: int ierr;
78: char *prefix;
81: st->numberofshifts = 1;
82: st->ops->apply = STApply_Shift;
83: st->ops->backtr = STBackTransform_Shift;
84: st->ops->destroy = STDestroy_Shift;
85: st->ops->setup = STSetUp_Shift;
87: if (st->B) {
88: KSPCreate(st->comm,&st->ksp);
89: STGetOptionsPrefix(st,&prefix);
90: KSPSetOptionsPrefix(st->ksp,prefix);
91: KSPAppendOptionsPrefix(st->ksp,"st_");
92: KSPSetOperators(st->ksp,st->B,st->B,DIFFERENT_NONZERO_PATTERN);
93: }
95: return(0);
96: }
97: EXTERN_C_END