Actual source code: ipform.c
1: /*
2: Routines for setting the matrix representation of the inner product.
4: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5: SLEPc - Scalable Library for Eigenvalue Problem Computations
6: Copyright (c) 2002-2011, Universitat Politecnica de Valencia, Spain
8: This file is part of SLEPc.
9:
10: SLEPc is free software: you can redistribute it and/or modify it under the
11: terms of version 3 of the GNU Lesser General Public License as published by
12: the Free Software Foundation.
14: SLEPc is distributed in the hope that it will be useful, but WITHOUT ANY
15: WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16: FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
17: more details.
19: You should have received a copy of the GNU Lesser General Public License
20: along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
21: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
22: */
24: #include <private/ipimpl.h> /*I "slepcip.h" I*/
28: /*@
29: IPSetMatrix - Specifies the matrix representation of the inner product.
31: Collective on IP
33: Input Parameters:
34: + ip - the inner product context
35: - mat - the matrix (may be PETSC_NULL)
37: Notes:
38: A PETSC_NULL has the same effect as if the identity matrix was passed.
40: This function is called by EPSSetProblemType() and usually need not be
41: called by the user.
43: Level: developer
45: .seealso: IPGetMatrix(), IPInnerProduct(), IPNorm(), EPSSetProblemType()
46: @*/
47: PetscErrorCode IPSetMatrix(IP ip,Mat mat)
48: {
53: if (mat) {
55: PetscObjectReference((PetscObject)mat);
56: }
57: IPReset(ip);
58: ip->matrix = mat;
59: if (mat) { MatGetVecs(mat,&ip->Bx,PETSC_NULL); }
60: return(0);
61: }
65: /*@C
66: IPGetMatrix - Retrieves the matrix representation of the inner product.
68: Not collective, though a parallel Mat may be returned
70: Input Parameter:
71: . ip - the inner product context
73: Output Parameter:
74: . mat - the matrix of the inner product (may be PETSC_NULL)
76: Level: developer
78: .seealso: IPSetMatrix(), IPInnerProduct(), IPNorm(), EPSSetProblemType()
79: @*/
80: PetscErrorCode IPGetMatrix(IP ip,Mat* mat)
81: {
85: *mat = ip->matrix;
86: return(0);
87: }
91: PetscErrorCode IPApplyMatrix_Private(IP ip,Vec x)
92: {
96: if (((PetscObject)x)->id != ip->xid || ((PetscObject)x)->state != ip->xstate) {
97: PetscLogEventBegin(IP_ApplyMatrix,ip,0,0,0);
98: MatMult(ip->matrix,x,ip->Bx);
99: ip->xid = ((PetscObject)x)->id;
100: ip->xstate = ((PetscObject)x)->state;
101: PetscLogEventEnd(IP_ApplyMatrix,ip,0,0,0);
102: }
103: return(0);
104: }
108: /*@
109: IPApplyMatrix - Multiplies a vector by the matrix representing the IP.
111: Neighbor-wise Collective on IP and Vec
113: Input Parameters:
114: + ip - the inner product context
115: - x - the vector
117: Output Parameter:
118: . y - the result
120: Note:
121: If no matrix was specified this function copies the vector.
123: Level: developer
125: .seealso: IPSetMatrix(), IPInnerProduct(), IPNorm(), EPSSetProblemType()
126: @*/
127: PetscErrorCode IPApplyMatrix(IP ip,Vec x,Vec y)
128: {
133: if (ip->matrix) {
134: IPApplyMatrix_Private(ip,x);
135: VecCopy(ip->Bx,y);
136: } else {
137: VecCopy(x,y);
138: }
139: return(0);
140: }