| 1249 |
slepc |
1 |
/*
|
|
|
2 |
SVD routines for setting up the solver.
|
|
|
3 |
*/
|
|
|
4 |
#include "src/svd/svdimpl.h" /*I "slepcsvd.h" I*/
|
|
|
5 |
|
|
|
6 |
#undef __FUNCT__
|
|
|
7 |
#define __FUNCT__ "SVDSetOperator"
|
|
|
8 |
/*@C
|
|
|
9 |
SVDSetOperator - Set the matrix associated with the singular value problem.
|
|
|
10 |
|
|
|
11 |
Collective on SVD and Mat
|
|
|
12 |
|
|
|
13 |
Input Parameters:
|
|
|
14 |
+ svd - the singular value solver context
|
|
|
15 |
- A - the matrix associated with the singular value problem
|
|
|
16 |
|
|
|
17 |
Level: beginner
|
|
|
18 |
|
|
|
19 |
.seealso: SVDSolve(), SVDGetOperators()
|
|
|
20 |
@*/
|
|
|
21 |
PetscErrorCode SVDSetOperator(SVD svd,Mat mat)
|
|
|
22 |
{
|
|
|
23 |
PetscErrorCode ierr;
|
|
|
24 |
|
|
|
25 |
PetscFunctionBegin;
|
|
|
26 |
PetscValidHeaderSpecific(svd,SVD_COOKIE,1);
|
|
|
27 |
PetscValidHeaderSpecific(mat,MAT_COOKIE,2);
|
|
|
28 |
PetscCheckSameComm(svd,1,mat,2);
|
|
|
29 |
ierr = PetscObjectReference((PetscObject)mat);CHKERRQ(ierr);
|
|
|
30 |
if (svd->A) {
|
|
|
31 |
ierr = MatDestroy(svd->A);CHKERRQ(ierr);
|
|
|
32 |
}
|
|
|
33 |
svd->A = mat;
|
|
|
34 |
svd->setupcalled = 0;
|
|
|
35 |
PetscFunctionReturn(0);
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
#undef __FUNCT__
|
|
|
39 |
#define __FUNCT__ "SVDGetOperator"
|
|
|
40 |
/*@C
|
|
|
41 |
SVDGetOperator - Get the matrix associated with the singular value problem.
|
|
|
42 |
|
|
|
43 |
Not collective, though parallel Mats are returned if the SVD is parallel
|
|
|
44 |
|
|
|
45 |
Input Parameter:
|
|
|
46 |
. svd - the singular value solver context
|
|
|
47 |
|
|
|
48 |
Output Parameters:
|
|
|
49 |
. A - the matrix associated with the singular value problem
|
|
|
50 |
|
|
|
51 |
Level: intermediate
|
|
|
52 |
|
|
|
53 |
.seealso: SVDSetOperator()
|
|
|
54 |
@*/
|
|
|
55 |
PetscErrorCode SVDGetOperator(SVD svd,Mat *A)
|
|
|
56 |
{
|
|
|
57 |
PetscFunctionBegin;
|
|
|
58 |
PetscValidHeaderSpecific(svd,SVD_COOKIE,1);
|
|
|
59 |
PetscValidPointer(A,2);
|
|
|
60 |
*A = svd->A;
|
|
|
61 |
PetscFunctionReturn(0);
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
#undef __FUNCT__
|
|
|
65 |
#define __FUNCT__ "SVDSetFromOptions"
|
|
|
66 |
/*@
|
|
|
67 |
SVDSetFromOptions - Sets SVD options from the options database.
|
|
|
68 |
This routine must be called before SVDSetUp() if the user is to be
|
|
|
69 |
allowed to set the solver type.
|
|
|
70 |
|
|
|
71 |
Collective on SVD
|
|
|
72 |
|
|
|
73 |
Input Parameters:
|
|
|
74 |
. svd - the singular value solver context
|
|
|
75 |
|
|
|
76 |
Notes:
|
|
|
77 |
To see all options, run your program with the -help option.
|
|
|
78 |
|
|
|
79 |
Level: beginner
|
|
|
80 |
|
|
|
81 |
.seealso:
|
|
|
82 |
@*/
|
|
|
83 |
PetscErrorCode SVDSetFromOptions(SVD svd)
|
|
|
84 |
{
|
|
|
85 |
PetscErrorCode ierr;
|
|
|
86 |
char type[256];
|
|
|
87 |
PetscTruth flg;
|
|
|
88 |
|
|
|
89 |
PetscFunctionBegin;
|
|
|
90 |
PetscValidHeaderSpecific(svd,SVD_COOKIE,1);
|
| 1253 |
slepc |
91 |
svd->setupcalled = 0;
|
| 1249 |
slepc |
92 |
ierr = PetscOptionsBegin(svd->comm,svd->prefix,"Singular Value Solver (SVD) Options","SVD");CHKERRQ(ierr);
|
|
|
93 |
|
|
|
94 |
ierr = PetscOptionsList("-svd_type","Singular Value Solver method","SVDSetType",SVDList,(char*)(svd->type_name?svd->type_name:SVDEIGENSOLVER),type,256,&flg);CHKERRQ(ierr);
|
|
|
95 |
if (flg) {
|
|
|
96 |
ierr = SVDSetType(svd,type);CHKERRQ(ierr);
|
|
|
97 |
} else if (!svd->type_name) {
|
|
|
98 |
ierr = SVDSetType(svd,SVDEIGENSOLVER);CHKERRQ(ierr);
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
ierr = PetscOptionsName("-svd_view","Print detailed information on solver used","SVDiew",0);CHKERRQ(ierr);
|
|
|
102 |
|
|
|
103 |
if (svd->ops->setfromoptions) {
|
|
|
104 |
ierr = (*svd->ops->setfromoptions)(svd);CHKERRQ(ierr);
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
ierr = PetscOptionsEnd();CHKERRQ(ierr);
|
|
|
108 |
PetscFunctionReturn(0);
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
#undef __FUNCT__
|
|
|
112 |
#define __FUNCT__ "SVDSetUp"
|
|
|
113 |
/*@
|
|
|
114 |
SVDSetUp - Sets up all the internal data structures necessary for the
|
|
|
115 |
execution of the singular value solver.
|
|
|
116 |
|
|
|
117 |
Collective on SVD
|
|
|
118 |
|
|
|
119 |
Input Parameter:
|
|
|
120 |
. SVD - singular value solver context
|
|
|
121 |
|
|
|
122 |
Level: advanced
|
|
|
123 |
|
|
|
124 |
Notes:
|
|
|
125 |
This function need not be called explicitly in most cases, since SVDSolve()
|
|
|
126 |
calls it. It can be useful when one wants to measure the set-up time
|
|
|
127 |
separately from the solve time.
|
|
|
128 |
|
|
|
129 |
.seealso: SVDCreate(), SVDSolve(), SVDDestroy()
|
|
|
130 |
@*/
|
|
|
131 |
PetscErrorCode SVDSetUp(SVD svd)
|
|
|
132 |
{
|
|
|
133 |
PetscErrorCode ierr;
|
|
|
134 |
|
|
|
135 |
PetscFunctionBegin;
|
|
|
136 |
PetscValidHeaderSpecific(svd,SVD_COOKIE,1);
|
|
|
137 |
if (svd->setupcalled) PetscFunctionReturn(0);
|
|
|
138 |
ierr = PetscLogEventBegin(SVD_SetUp,svd,0,0,0);CHKERRQ(ierr);
|
|
|
139 |
|
|
|
140 |
/* Set default solver type */
|
|
|
141 |
if (!svd->type_name) {
|
|
|
142 |
ierr = SVDSetType(svd,SVDEIGENSOLVER);CHKERRQ(ierr);
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
/* check matrix */
|
|
|
146 |
if (!svd->A) {
|
|
|
147 |
SETERRQ(PETSC_ERR_ARG_WRONGSTATE, "SVDSetOperator must be called first");
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
/* call specific solver setup */
|
|
|
151 |
ierr = (*svd->ops->setup)(svd);CHKERRQ(ierr);
|
|
|
152 |
|
|
|
153 |
ierr = PetscLogEventEnd(SVD_SetUp,svd,0,0,0);CHKERRQ(ierr);
|
|
|
154 |
svd->setupcalled = 1;
|
|
|
155 |
PetscFunctionReturn(0);
|
|
|
156 |
}
|