GCC Code Coverage Report


Directory: ./
File: include/slepc/private/stimpl.h
Date: 2025-10-04 04:19:13
Exec Total Coverage
Lines: 11 11 100.0%
Functions: 1 1 100.0%
Branches: 35 54 64.8%

Line Branch Exec Source
1 /*
2 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3 SLEPc - Scalable Library for Eigenvalue Problem Computations
4 Copyright (c) 2002-, Universitat Politecnica de Valencia, Spain
5
6 This file is part of SLEPc.
7 SLEPc is distributed under a 2-clause BSD license (see LICENSE).
8 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
9 */
10
11 #pragma once
12
13 #include <slepcst.h>
14 #include <slepc/private/slepcimpl.h>
15
16 /* SUBMANSEC = ST */
17
18 SLEPC_EXTERN PetscBool STRegisterAllCalled;
19 SLEPC_EXTERN PetscErrorCode STRegisterAll(void);
20 SLEPC_EXTERN PetscLogEvent ST_SetUp,ST_ComputeOperator,ST_Apply,ST_ApplyTranspose,ST_ApplyHermitianTranspose,ST_MatSetUp,ST_MatMult,ST_MatMultTranspose,ST_MatSolve,ST_MatSolveTranspose;
21
22 typedef struct _STOps *STOps;
23
24 struct _STOps {
25 PetscErrorCode (*apply)(ST,Vec,Vec);
26 PetscErrorCode (*applymat)(ST,Mat,Mat);
27 PetscErrorCode (*applytrans)(ST,Vec,Vec);
28 PetscErrorCode (*applyhermtrans)(ST,Vec,Vec);
29 PetscErrorCode (*backtransform)(ST,PetscInt,PetscScalar*,PetscScalar*);
30 PetscErrorCode (*setshift)(ST,PetscScalar);
31 PetscErrorCode (*getbilinearform)(ST,Mat*);
32 PetscErrorCode (*setup)(ST);
33 PetscErrorCode (*computeoperator)(ST);
34 PetscErrorCode (*setfromoptions)(ST,PetscOptionItems);
35 PetscErrorCode (*postsolve)(ST);
36 PetscErrorCode (*destroy)(ST);
37 PetscErrorCode (*reset)(ST);
38 PetscErrorCode (*view)(ST,PetscViewer);
39 PetscErrorCode (*checknullspace)(ST,BV);
40 PetscErrorCode (*setdefaultksp)(ST);
41 };
42
43 /*
44 'Updated' state means STSetUp must be called because matrices have been
45 modified, but the pattern is the same (hence reuse symbolic factorization)
46 */
47 typedef enum { ST_STATE_INITIAL,
48 ST_STATE_SETUP,
49 ST_STATE_UPDATED } STStateType;
50
51 struct _p_ST {
52 PETSCHEADER(struct _STOps);
53 /*------------------------- User parameters --------------------------*/
54 Mat *A; /* matrices that define the eigensystem */
55 PetscInt nmat; /* number of user-provided matrices */
56 PetscScalar sigma; /* value of the shift */
57 PetscScalar defsigma; /* default value of the shift */
58 STMatMode matmode; /* how the transformation matrix is handled */
59 MatStructure str; /* whether matrices have the same pattern or not */
60 PetscBool transform; /* whether transformed matrices are computed */
61 PetscBool structured; /* whether the operator is structured or not */
62 Vec D; /* diagonal matrix for balancing */
63 Mat Pmat; /* user-provided preconditioner matrix */
64 PetscBool Pmat_set; /* whether the user provided a preconditioner matrix or not */
65 Mat *Psplit; /* matrices for the split preconditioner */
66 PetscInt nsplit; /* number of split preconditioner matrices */
67 MatStructure strp; /* pattern of split preconditioner matrices */
68
69 /*------------------------- Misc data --------------------------*/
70 KSP ksp; /* linear solver used in some ST's */
71 PetscBool usesksp; /* whether the KSP object is used or not */
72 PetscInt nwork; /* number of work vectors */
73 Vec *work; /* work vectors */
74 Vec wb; /* balancing requires an extra work vector */
75 Vec wht; /* extra work vector for hermitian transpose apply */
76 STStateType state; /* initial -> setup -> with updated matrices */
77 PetscObjectState *Astate; /* matrix state (to identify the original matrices) */
78 Mat *T; /* matrices resulting from transformation */
79 Mat Op; /* shell matrix for operator = alpha*D*inv(P)*M*inv(D) */
80 PetscBool opseized; /* whether Op has been seized by user */
81 PetscBool opready; /* whether Op is up-to-date or need be computed */
82 Mat P; /* matrix from which preconditioner is built */
83 Mat M; /* matrix corresponding to the non-inverted part of the operator */
84 PetscBool sigma_set; /* whether the user provided the shift or not */
85 PetscBool asymm; /* the user matrices are all symmetric */
86 PetscBool aherm; /* the user matrices are all hermitian */
87 void *data;
88 };
89
90 /*
91 Macros to test valid ST arguments
92 */
93 #if !defined(PETSC_USE_DEBUG)
94
95 #define STCheckMatrices(h,arg) do {(void)(h);} while (0)
96 #define STCheckNotSeized(h,arg) do {(void)(h);} while (0)
97
98 #else
99
100 #define STCheckMatrices(h,arg) \
101 do { \
102 PetscCheck((h)->A,PetscObjectComm((PetscObject)(h)),PETSC_ERR_ARG_WRONGSTATE,"ST matrices have not been set: Parameter #%d",arg); \
103 } while (0)
104 #define STCheckNotSeized(h,arg) \
105 do { \
106 PetscCheck(!(h)->opseized,PetscObjectComm((PetscObject)(h)),PETSC_ERR_ARG_WRONGSTATE,"Must call STRestoreOperator() first: Parameter #%d",arg); \
107 } while (0)
108
109 #endif
110
111 SLEPC_INTERN PetscErrorCode STGetBilinearForm_Default(ST,Mat*);
112 SLEPC_INTERN PetscErrorCode STCheckNullSpace_Default(ST,BV);
113 SLEPC_INTERN PetscErrorCode STMatShellCreate(ST,PetscScalar,PetscInt,PetscInt*,PetscScalar*,Mat*);
114 SLEPC_INTERN PetscErrorCode STMatShellShift(Mat,PetscScalar);
115 SLEPC_INTERN PetscErrorCode STCheckFactorPackage(ST);
116 SLEPC_INTERN PetscErrorCode STMatMAXPY_Private(ST,PetscScalar,PetscScalar,PetscInt,PetscScalar*,PetscBool,PetscBool,Mat*);
117 SLEPC_INTERN PetscErrorCode STCoeffs_Monomial(ST,PetscScalar*);
118 SLEPC_INTERN PetscErrorCode STSetDefaultKSP(ST);
119 SLEPC_INTERN PetscErrorCode STSetDefaultKSP_Default(ST);
120 SLEPC_INTERN PetscErrorCode STIsInjective_Shell(ST,PetscBool*);
121 SLEPC_INTERN PetscErrorCode STComputeOperator(ST);
122 SLEPC_INTERN PetscErrorCode STGetOperator_Private(ST,Mat*);
123 SLEPC_INTERN PetscErrorCode STApply_Generic(ST,Vec,Vec);
124 SLEPC_INTERN PetscErrorCode STApplyMat_Generic(ST,Mat,Mat);
125 SLEPC_INTERN PetscErrorCode STApplyTranspose_Generic(ST,Vec,Vec);
126 SLEPC_INTERN PetscErrorCode STApplyHermitianTranspose_Generic(ST,Vec,Vec);
127
128 /*
129 ST_KSPSetOperators - Sets the KSP matrices
130 */
131 12538 static inline PetscErrorCode ST_KSPSetOperators(ST st,Mat A,Mat B)
132 {
133 12538 const char *prefix;
134
135
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
12538 PetscFunctionBegin;
136
6/8
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 50 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 16 times.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4 times.
12538 if (!st->ksp) PetscCall(STGetKSP(st,&st->ksp));
137
4/6
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 40 times.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10 times.
12538 PetscCall(STCheckFactorPackage(st));
138
4/6
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 40 times.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10 times.
12538 PetscCall(KSPSetOperators(st->ksp,A,B));
139
4/6
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 40 times.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10 times.
12538 PetscCall(MatGetOptionsPrefix(B,&prefix));
140
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 40 times.
12538 if (!prefix) {
141 /* set Mat prefix to be the same as KSP to enable setting command-line options (e.g. MUMPS)
142 only applies if the Mat has no user-defined prefix */
143
4/6
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 40 times.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10 times.
5625 PetscCall(KSPGetOptionsPrefix(st->ksp,&prefix));
144
4/6
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 40 times.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10 times.
5625 PetscCall(MatSetOptionsPrefix(B,prefix));
145 }
146
6/12
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 10 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 10 times.
2509 PetscFunctionReturn(PETSC_SUCCESS);
147 }
148