| 1913 |
jroman |
1 |
/*
|
|
|
2 |
|
|
|
3 |
Linearization for gyroscopic QEP, companion form 1.
|
|
|
4 |
|
|
|
5 |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
6 |
SLEPc - Scalable Library for Eigenvalue Problem Computations
|
| 2575 |
eromero |
7 |
Copyright (c) 2002-2011, Universitat Politecnica de Valencia, Spain
|
| 1913 |
jroman |
8 |
|
|
|
9 |
This file is part of SLEPc.
|
|
|
10 |
|
|
|
11 |
SLEPc is free software: you can redistribute it and/or modify it under the
|
|
|
12 |
terms of version 3 of the GNU Lesser General Public License as published by
|
|
|
13 |
the Free Software Foundation.
|
|
|
14 |
|
|
|
15 |
SLEPc is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
16 |
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
17 |
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
|
|
|
18 |
more details.
|
|
|
19 |
|
|
|
20 |
You should have received a copy of the GNU Lesser General Public License
|
|
|
21 |
along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
|
|
|
22 |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
23 |
*/
|
|
|
24 |
|
| 2729 |
jroman |
25 |
#include <slepc-private/qepimpl.h> /*I "slepcqep.h" I*/
|
| 1913 |
jroman |
26 |
#include "linearp.h"
|
|
|
27 |
|
|
|
28 |
/*
|
|
|
29 |
Given the quadratic problem (l^2*M + l*C + K)*x = 0 the following
|
|
|
30 |
linearization is employed:
|
|
|
31 |
|
|
|
32 |
A*z = l*B*z where A = [ K 0 ] B = [ 0 K ] z = [ x ]
|
|
|
33 |
[ C K ] [-M 0 ] [ l*x ]
|
|
|
34 |
*/
|
|
|
35 |
|
|
|
36 |
#undef __FUNCT__
|
| 2324 |
jroman |
37 |
#define __FUNCT__ "MatMult_Linear_H1A"
|
|
|
38 |
PetscErrorCode MatMult_Linear_H1A(Mat A,Vec x,Vec y)
|
| 1913 |
jroman |
39 |
{
|
| 2334 |
jroman |
40 |
PetscErrorCode ierr;
|
|
|
41 |
QEP_LINEAR *ctx;
|
|
|
42 |
const PetscScalar *px;
|
|
|
43 |
PetscScalar *py;
|
|
|
44 |
PetscInt m;
|
| 1913 |
jroman |
45 |
|
|
|
46 |
PetscFunctionBegin;
|
|
|
47 |
ierr = MatShellGetContext(A,(void**)&ctx);CHKERRQ(ierr);
|
|
|
48 |
ierr = MatGetLocalSize(ctx->M,&m,PETSC_NULL);CHKERRQ(ierr);
|
| 2334 |
jroman |
49 |
ierr = VecGetArrayRead(x,&px);CHKERRQ(ierr);
|
| 1913 |
jroman |
50 |
ierr = VecGetArray(y,&py);CHKERRQ(ierr);
|
|
|
51 |
ierr = VecPlaceArray(ctx->x1,px);CHKERRQ(ierr);
|
|
|
52 |
ierr = VecPlaceArray(ctx->x2,px+m);CHKERRQ(ierr);
|
|
|
53 |
ierr = VecPlaceArray(ctx->y1,py);CHKERRQ(ierr);
|
|
|
54 |
ierr = VecPlaceArray(ctx->y2,py+m);CHKERRQ(ierr);
|
|
|
55 |
/* y2 = C*x1 + K*x2 */
|
|
|
56 |
ierr = MatMult(ctx->C,ctx->x1,ctx->y1);CHKERRQ(ierr);
|
|
|
57 |
ierr = MatMult(ctx->K,ctx->x2,ctx->y2);CHKERRQ(ierr);
|
| 1919 |
jroman |
58 |
ierr = VecAXPY(ctx->y2,ctx->sfactor,ctx->y1);CHKERRQ(ierr);
|
| 1913 |
jroman |
59 |
/* y1 = K*x1 */
|
|
|
60 |
ierr = MatMult(ctx->K,ctx->x1,ctx->y1);CHKERRQ(ierr);
|
|
|
61 |
ierr = VecResetArray(ctx->x1);CHKERRQ(ierr);
|
|
|
62 |
ierr = VecResetArray(ctx->x2);CHKERRQ(ierr);
|
|
|
63 |
ierr = VecResetArray(ctx->y1);CHKERRQ(ierr);
|
|
|
64 |
ierr = VecResetArray(ctx->y2);CHKERRQ(ierr);
|
| 2334 |
jroman |
65 |
ierr = VecRestoreArrayRead(x,&px);CHKERRQ(ierr);
|
| 1913 |
jroman |
66 |
ierr = VecRestoreArray(y,&py);CHKERRQ(ierr);
|
|
|
67 |
PetscFunctionReturn(0);
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
#undef __FUNCT__
|
| 2324 |
jroman |
71 |
#define __FUNCT__ "MatMult_Linear_H1B"
|
|
|
72 |
PetscErrorCode MatMult_Linear_H1B(Mat B,Vec x,Vec y)
|
| 1913 |
jroman |
73 |
{
|
| 2334 |
jroman |
74 |
PetscErrorCode ierr;
|
|
|
75 |
QEP_LINEAR *ctx;
|
|
|
76 |
const PetscScalar *px;
|
|
|
77 |
PetscScalar *py;
|
|
|
78 |
PetscInt m;
|
| 1913 |
jroman |
79 |
|
|
|
80 |
PetscFunctionBegin;
|
|
|
81 |
ierr = MatShellGetContext(B,(void**)&ctx);CHKERRQ(ierr);
|
|
|
82 |
ierr = MatGetLocalSize(ctx->M,&m,PETSC_NULL);CHKERRQ(ierr);
|
| 2334 |
jroman |
83 |
ierr = VecGetArrayRead(x,&px);CHKERRQ(ierr);
|
| 1913 |
jroman |
84 |
ierr = VecGetArray(y,&py);CHKERRQ(ierr);
|
|
|
85 |
ierr = VecPlaceArray(ctx->x1,px);CHKERRQ(ierr);
|
|
|
86 |
ierr = VecPlaceArray(ctx->x2,px+m);CHKERRQ(ierr);
|
|
|
87 |
ierr = VecPlaceArray(ctx->y1,py);CHKERRQ(ierr);
|
|
|
88 |
ierr = VecPlaceArray(ctx->y2,py+m);CHKERRQ(ierr);
|
|
|
89 |
/* y1 = K*x2 */
|
| 1919 |
jroman |
90 |
ierr = MatMult(ctx->K,ctx->x2,ctx->y1);CHKERRQ(ierr);
|
| 1913 |
jroman |
91 |
/* y2 = -M*x1 */
|
|
|
92 |
ierr = MatMult(ctx->M,ctx->x1,ctx->y2);CHKERRQ(ierr);
|
| 1919 |
jroman |
93 |
ierr = VecScale(ctx->y2,-ctx->sfactor*ctx->sfactor);CHKERRQ(ierr);
|
| 1913 |
jroman |
94 |
ierr = VecResetArray(ctx->x1);CHKERRQ(ierr);
|
|
|
95 |
ierr = VecResetArray(ctx->x2);CHKERRQ(ierr);
|
|
|
96 |
ierr = VecResetArray(ctx->y1);CHKERRQ(ierr);
|
|
|
97 |
ierr = VecResetArray(ctx->y2);CHKERRQ(ierr);
|
| 2334 |
jroman |
98 |
ierr = VecRestoreArrayRead(x,&px);CHKERRQ(ierr);
|
| 1913 |
jroman |
99 |
ierr = VecRestoreArray(y,&py);CHKERRQ(ierr);
|
|
|
100 |
PetscFunctionReturn(0);
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
#undef __FUNCT__
|
| 2324 |
jroman |
104 |
#define __FUNCT__ "MatGetDiagonal_Linear_H1A"
|
|
|
105 |
PetscErrorCode MatGetDiagonal_Linear_H1A(Mat A,Vec diag)
|
| 1913 |
jroman |
106 |
{
|
|
|
107 |
PetscErrorCode ierr;
|
|
|
108 |
QEP_LINEAR *ctx;
|
|
|
109 |
PetscScalar *pd;
|
|
|
110 |
PetscInt m;
|
|
|
111 |
|
|
|
112 |
PetscFunctionBegin;
|
|
|
113 |
ierr = MatShellGetContext(A,(void**)&ctx);CHKERRQ(ierr);
|
|
|
114 |
ierr = MatGetLocalSize(ctx->M,&m,PETSC_NULL);CHKERRQ(ierr);
|
|
|
115 |
ierr = VecGetArray(diag,&pd);CHKERRQ(ierr);
|
|
|
116 |
ierr = VecPlaceArray(ctx->x1,pd);CHKERRQ(ierr);
|
|
|
117 |
ierr = VecPlaceArray(ctx->x2,pd+m);CHKERRQ(ierr);
|
|
|
118 |
ierr = MatGetDiagonal(ctx->K,ctx->x1);CHKERRQ(ierr);
|
|
|
119 |
ierr = VecCopy(ctx->x1,ctx->x2);CHKERRQ(ierr);
|
|
|
120 |
ierr = VecResetArray(ctx->x1);CHKERRQ(ierr);
|
|
|
121 |
ierr = VecResetArray(ctx->x2);CHKERRQ(ierr);
|
|
|
122 |
ierr = VecRestoreArray(diag,&pd);CHKERRQ(ierr);
|
|
|
123 |
PetscFunctionReturn(0);
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
#undef __FUNCT__
|
| 2324 |
jroman |
127 |
#define __FUNCT__ "MatGetDiagonal_Linear_H1B"
|
|
|
128 |
PetscErrorCode MatGetDiagonal_Linear_H1B(Mat B,Vec diag)
|
| 1913 |
jroman |
129 |
{
|
|
|
130 |
PetscErrorCode ierr;
|
|
|
131 |
|
|
|
132 |
PetscFunctionBegin;
|
|
|
133 |
ierr = VecSet(diag,0.0);CHKERRQ(ierr);
|
|
|
134 |
PetscFunctionReturn(0);
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
#undef __FUNCT__
|
| 2324 |
jroman |
138 |
#define __FUNCT__ "MatCreateExplicit_Linear_H1A"
|
|
|
139 |
PetscErrorCode MatCreateExplicit_Linear_H1A(MPI_Comm comm,QEP_LINEAR *ctx,Mat *A)
|
| 1913 |
jroman |
140 |
{
|
|
|
141 |
PetscErrorCode ierr;
|
|
|
142 |
|
|
|
143 |
PetscFunctionBegin;
|
| 2296 |
jroman |
144 |
ierr = SlepcMatTile(1.0,ctx->K,0.0,ctx->K,ctx->sfactor,ctx->C,1.0,ctx->K,A);CHKERRQ(ierr);
|
| 1913 |
jroman |
145 |
PetscFunctionReturn(0);
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
#undef __FUNCT__
|
| 2324 |
jroman |
149 |
#define __FUNCT__ "MatCreateExplicit_Linear_H1B"
|
|
|
150 |
PetscErrorCode MatCreateExplicit_Linear_H1B(MPI_Comm comm,QEP_LINEAR *ctx,Mat *B)
|
| 1913 |
jroman |
151 |
{
|
|
|
152 |
PetscErrorCode ierr;
|
|
|
153 |
|
|
|
154 |
PetscFunctionBegin;
|
| 2296 |
jroman |
155 |
ierr = SlepcMatTile(0.0,ctx->K,1.0,ctx->K,-ctx->sfactor*ctx->sfactor,ctx->M,0.0,ctx->K,B);CHKERRQ(ierr);
|
| 1913 |
jroman |
156 |
PetscFunctionReturn(0);
|
|
|
157 |
}
|
|
|
158 |
|