| 1329 |
slepc |
1 |
/*
|
|
|
2 |
Routines for setting the bilinear form
|
| 1376 |
slepc |
3 |
|
|
|
4 |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 1672 |
slepc |
5 |
SLEPc - Scalable Library for Eigenvalue Problem Computations
|
| 2116 |
eromero |
6 |
Copyright (c) 2002-2010, Universidad Politecnica de Valencia, Spain
|
| 1376 |
slepc |
7 |
|
| 1672 |
slepc |
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.
|
|
|
13 |
|
|
|
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.
|
|
|
18 |
|
|
|
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/>.
|
| 1376 |
slepc |
21 |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 1329 |
slepc |
22 |
*/
|
| 1376 |
slepc |
23 |
|
| 1521 |
slepc |
24 |
#include "private/ipimpl.h" /*I "slepcip.h" I*/
|
| 1329 |
slepc |
25 |
|
|
|
26 |
#undef __FUNCT__
|
|
|
27 |
#define __FUNCT__ "IPSetBilinearForm"
|
| 1345 |
slepc |
28 |
/*@
|
|
|
29 |
IPSetBilinearForm - Specifies the bilinear form to be used for
|
|
|
30 |
inner products.
|
|
|
31 |
|
|
|
32 |
Collective on IP
|
|
|
33 |
|
|
|
34 |
Input Parameters:
|
|
|
35 |
+ ip - the inner product context
|
|
|
36 |
. mat - the matrix of the bilinear form (may be PETSC_NULL)
|
|
|
37 |
- form - the type of bilinear form
|
|
|
38 |
|
|
|
39 |
Note:
|
|
|
40 |
This function is called by EPSSetProblemType() and usually need not be
|
|
|
41 |
called by the user.
|
|
|
42 |
|
|
|
43 |
Level: developer
|
|
|
44 |
|
| 1364 |
slepc |
45 |
.seealso: IPGetBilinearForm(), IPInnerProduct(), IPNorm(), EPSSetProblemType(),
|
|
|
46 |
IPBilinearForm
|
| 1345 |
slepc |
47 |
@*/
|
| 1329 |
slepc |
48 |
PetscErrorCode IPSetBilinearForm(IP ip,Mat mat,IPBilinearForm form)
|
|
|
49 |
{
|
|
|
50 |
PetscErrorCode ierr;
|
|
|
51 |
|
|
|
52 |
PetscFunctionBegin;
|
| 2213 |
jroman |
53 |
PetscValidHeaderSpecific(ip,IP_CLASSID,1);
|
| 1329 |
slepc |
54 |
if (mat) {
|
| 2213 |
jroman |
55 |
PetscValidHeaderSpecific(mat,MAT_CLASSID,1);
|
| 1329 |
slepc |
56 |
PetscObjectReference((PetscObject)mat);
|
|
|
57 |
}
|
|
|
58 |
if (ip->matrix) {
|
|
|
59 |
ierr = MatDestroy(ip->matrix);CHKERRQ(ierr);
|
| 1358 |
slepc |
60 |
ierr = VecDestroy(ip->Bx);CHKERRQ(ierr);
|
| 1329 |
slepc |
61 |
}
|
|
|
62 |
ip->matrix = mat;
|
|
|
63 |
ip->bilinear_form = form;
|
| 1358 |
slepc |
64 |
ip->xid = ip->xstate = 0;
|
|
|
65 |
if (mat) { ierr = MatGetVecs(mat,&ip->Bx,PETSC_NULL);CHKERRQ(ierr); }
|
| 1329 |
slepc |
66 |
PetscFunctionReturn(0);
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
#undef __FUNCT__
|
|
|
70 |
#define __FUNCT__ "IPGetBilinearForm"
|
| 1345 |
slepc |
71 |
/*@C
|
|
|
72 |
IPGetBilinearForm - Retrieves the bilinear form to be used for
|
|
|
73 |
inner products.
|
|
|
74 |
|
|
|
75 |
Input Parameter:
|
| 1349 |
slepc |
76 |
. ip - the inner product context
|
| 1345 |
slepc |
77 |
|
|
|
78 |
Output Parameter:
|
|
|
79 |
+ mat - the matrix of the bilinear form (may be PETSC_NULL)
|
|
|
80 |
- form - the type of bilinear form
|
|
|
81 |
|
|
|
82 |
Level: developer
|
|
|
83 |
|
| 1364 |
slepc |
84 |
.seealso: IPSetBilinearForm(), IPInnerProduct(), IPNorm(), EPSSetProblemType(),
|
|
|
85 |
IPBilinearForm
|
| 1345 |
slepc |
86 |
@*/
|
| 1329 |
slepc |
87 |
PetscErrorCode IPGetBilinearForm(IP ip,Mat* mat,IPBilinearForm* form)
|
|
|
88 |
{
|
|
|
89 |
PetscFunctionBegin;
|
| 2213 |
jroman |
90 |
PetscValidHeaderSpecific(ip,IP_CLASSID,1);
|
| 1329 |
slepc |
91 |
if (mat) *mat = ip->matrix;
|
|
|
92 |
if (form) *form = ip->bilinear_form;
|
|
|
93 |
PetscFunctionReturn(0);
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
#undef __FUNCT__
|
| 1358 |
slepc |
97 |
#define __FUNCT__ "IPApplyMatrix_Private"
|
|
|
98 |
PetscErrorCode IPApplyMatrix_Private(IP ip,Vec x)
|
|
|
99 |
{
|
|
|
100 |
PetscErrorCode ierr;
|
|
|
101 |
|
|
|
102 |
PetscFunctionBegin;
|
| 1422 |
slepc |
103 |
if (((PetscObject)x)->id != ip->xid || ((PetscObject)x)->state != ip->xstate) {
|
| 1358 |
slepc |
104 |
ierr = PetscLogEventBegin(IP_ApplyMatrix,ip,0,0,0);CHKERRQ(ierr);
|
|
|
105 |
ierr = MatMult(ip->matrix,x,ip->Bx);CHKERRQ(ierr);
|
| 1422 |
slepc |
106 |
ip->xid = ((PetscObject)x)->id;
|
|
|
107 |
ip->xstate = ((PetscObject)x)->state;
|
| 1358 |
slepc |
108 |
ierr = PetscLogEventEnd(IP_ApplyMatrix,ip,0,0,0);CHKERRQ(ierr);
|
|
|
109 |
}
|
|
|
110 |
PetscFunctionReturn(0);
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
#undef __FUNCT__
|
| 1329 |
slepc |
114 |
#define __FUNCT__ "IPApplyMatrix"
|
| 1345 |
slepc |
115 |
/*@
|
|
|
116 |
IPApplyMatrix - Multiplies a vector with the matrix associated to the
|
|
|
117 |
bilinear form.
|
|
|
118 |
|
|
|
119 |
Collective on IP
|
|
|
120 |
|
|
|
121 |
Input Parameters:
|
|
|
122 |
+ ip - the inner product context
|
|
|
123 |
- x - the vector
|
|
|
124 |
|
|
|
125 |
Output Parameter:
|
|
|
126 |
. y - the result
|
|
|
127 |
|
|
|
128 |
Note:
|
|
|
129 |
If the bilinear form has no associated matrix this function copies the vector.
|
|
|
130 |
|
|
|
131 |
Level: developer
|
|
|
132 |
|
|
|
133 |
.seealso: IPSetBilinearForm(), IPInnerProduct(), IPNorm(), EPSSetProblemType()
|
|
|
134 |
@*/
|
| 1329 |
slepc |
135 |
PetscErrorCode IPApplyMatrix(IP ip,Vec x,Vec y)
|
|
|
136 |
{
|
|
|
137 |
PetscErrorCode ierr;
|
|
|
138 |
|
|
|
139 |
PetscFunctionBegin;
|
| 2213 |
jroman |
140 |
PetscValidHeaderSpecific(ip,IP_CLASSID,1);
|
| 1329 |
slepc |
141 |
if (ip->matrix) {
|
| 1358 |
slepc |
142 |
ierr = IPApplyMatrix_Private(ip,x);CHKERRQ(ierr);
|
|
|
143 |
ierr = VecCopy(ip->Bx,y);CHKERRQ(ierr);
|
| 1329 |
slepc |
144 |
} else {
|
|
|
145 |
ierr = VecCopy(x,y);CHKERRQ(ierr);
|
|
|
146 |
}
|
|
|
147 |
PetscFunctionReturn(0);
|
|
|
148 |
}
|