Actual source code: stsles.c
2: /*
3: The ST (spectral transformation) interface routines related to the
4: KSP object associated to it.
5: */
7: #include src/st/stimpl.h
11: /*@C
12: STAssociatedKSPSolve - Solves the linear system of equations associated
13: to the spectral transformation.
15: Collective on ST
17: Input Parameters:
18: . st - the spectral transformation context
19: . b - right hand side vector
21: Output Parameter:
22: . x - computed solution
24: Level: developer
26: .seealso: STGetKSP(), KSPSolve()
27: @*/
28: int STAssociatedKSPSolve(ST st,Vec b,Vec x)
29: {
30: int ierr,its;
31: KSPConvergedReason reason;
37: if (!st->ksp) { SETERRQ(PETSC_ERR_SUP,"ST has no associated KSP"); }
38: KSPSetRhs(st->ksp,b);
39: KSPSetSolution(st->ksp,x);
40: KSPSolve(st->ksp);
41: KSPGetConvergedReason(st->ksp,&reason);
42: if (reason<0) { SETERRQ1(0,"Warning: KSP did not converge (%d)",reason); }
43: KSPGetIterationNumber(st->ksp,&its);
44: st->lineariterations += its;
45: PetscLogInfo(st,"ST: linear solve iterations=%d\n",its);
46: return(0);
47: }
51: /*@
52: STSetKSP - Sets the KSP object associated with the spectral
53: transformation.
55: Not collective
57: Input Parameters:
58: + st - the spectral transformation context
59: - ksp - the linear system context
61: Level: advanced
63: @*/
64: int STSetKSP(ST st,KSP ksp)
65: {
70: st->ksp = ksp;
71: return(0);
72: }
76: /*@
77: STGetKSP - Gets the KSP object associated with the spectral
78: transformation.
80: Not collective
82: Input Parameter:
83: . st - the spectral transformation context
85: Output Parameter:
86: . ksp - the linear system context
88: Notes:
89: On output, the value of ksp can be PETSC_NULL if the combination of
90: eigenproblem type and selected transformation does not require to
91: solve a linear system of equations.
92:
93: Level: intermediate
95: @*/
96: int STGetKSP(ST st,KSP* ksp)
97: {
100: if (!st->type_name) { SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"Must call STSetType first"); }
101: if (ksp) *ksp = st->ksp;
102: return(0);
103: }
107: /*@
108: STGetNumberLinearIterations - Gets the total number of linear iterations
109: used by the ST object.
111: Not Collective
113: Input Parameter:
114: . st - the spectral transformation context
116: Output Parameter:
117: . lits - number of linear iterations
119: Level: intermediate
121: .seealso: STResetNumberLinearIterations()
122: @*/
123: int STGetNumberLinearIterations(ST st,int* lits)
124: {
128: *lits = st->lineariterations;
129: return(0);
130: }
134: /*@
135: STResetNumberLinearIterations - Resets the counter for total number of
136: linear iterations used by the ST object.
138: Collective on ST
140: Input Parameter:
141: . st - the spectral transformation context
143: Level: intermediate
145: .seealso: STGetNumberLinearIterations()
146: @*/
147: int STResetNumberLinearIterations(ST st)
148: {
151: st->lineariterations = 0;
152: return(0);
153: }