Actual source code: stimpl.h

slepc-3.20.2 2024-03-15
Report Typos and Errors
  1: /*
  2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
  4:    Copyright (c) 2002-, Universitat Politecnica de Valencia, Spain

  6:    This file is part of SLEPc.
  7:    SLEPc is distributed under a 2-clause BSD license (see LICENSE).
  8:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9: */

 11: #pragma once

 13: #include <slepcst.h>
 14: #include <slepc/private/slepcimpl.h>

 16: /* SUBMANSEC = ST */

 18: SLEPC_EXTERN PetscBool STRegisterAllCalled;
 19: SLEPC_EXTERN PetscErrorCode STRegisterAll(void);
 20: SLEPC_EXTERN PetscLogEvent ST_SetUp,ST_ComputeOperator,ST_Apply,ST_ApplyTranspose,ST_MatSetUp,ST_MatMult,ST_MatMultTranspose,ST_MatSolve,ST_MatSolveTranspose;

 22: typedef struct _STOps *STOps;

 24: struct _STOps {
 25:   PetscErrorCode (*apply)(ST,Vec,Vec);
 26:   PetscErrorCode (*applymat)(ST,Mat,Mat);
 27:   PetscErrorCode (*applytrans)(ST,Vec,Vec);
 28:   PetscErrorCode (*backtransform)(ST,PetscInt,PetscScalar*,PetscScalar*);
 29:   PetscErrorCode (*setshift)(ST,PetscScalar);
 30:   PetscErrorCode (*getbilinearform)(ST,Mat*);
 31:   PetscErrorCode (*setup)(ST);
 32:   PetscErrorCode (*computeoperator)(ST);
 33:   PetscErrorCode (*setfromoptions)(ST,PetscOptionItems*);
 34:   PetscErrorCode (*postsolve)(ST);
 35:   PetscErrorCode (*destroy)(ST);
 36:   PetscErrorCode (*reset)(ST);
 37:   PetscErrorCode (*view)(ST,PetscViewer);
 38:   PetscErrorCode (*checknullspace)(ST,BV);
 39:   PetscErrorCode (*setdefaultksp)(ST);
 40: };

 42: /*
 43:      'Updated' state means STSetUp must be called because matrices have been
 44:      modified, but the pattern is the same (hence reuse symbolic factorization)
 45: */
 46: typedef enum { ST_STATE_INITIAL,
 47:                ST_STATE_SETUP,
 48:                ST_STATE_UPDATED } STStateType;

 50: struct _p_ST {
 51:   PETSCHEADER(struct _STOps);
 52:   /*------------------------- User parameters --------------------------*/
 53:   Mat              *A;               /* matrices that define the eigensystem */
 54:   PetscInt         nmat;             /* number of user-provided matrices */
 55:   PetscScalar      sigma;            /* value of the shift */
 56:   PetscScalar      defsigma;         /* default value of the shift */
 57:   STMatMode        matmode;          /* how the transformation matrix is handled */
 58:   MatStructure     str;              /* whether matrices have the same pattern or not */
 59:   PetscBool        transform;        /* whether transformed matrices are computed */
 60:   Vec              D;                /* diagonal matrix for balancing */
 61:   Mat              Pmat;             /* user-provided preconditioner matrix */
 62:   PetscBool        Pmat_set;         /* whether the user provided a preconditioner matrix or not  */
 63:   Mat              *Psplit;          /* matrices for the split preconditioner */
 64:   PetscInt         nsplit;           /* number of split preconditioner matrices */
 65:   MatStructure     strp;             /* pattern of split preconditioner matrices */

 67:   /*------------------------- Misc data --------------------------*/
 68:   KSP              ksp;              /* linear solver used in some ST's */
 69:   PetscBool        usesksp;          /* whether the KSP object is used or not */
 70:   PetscInt         nwork;            /* number of work vectors */
 71:   Vec              *work;            /* work vectors */
 72:   Vec              wb;               /* balancing requires an extra work vector */
 73:   Vec              wht;              /* extra work vector for hermitian transpose apply */
 74:   STStateType      state;            /* initial -> setup -> with updated matrices */
 75:   PetscObjectState *Astate;          /* matrix state (to identify the original matrices) */
 76:   Mat              *T;               /* matrices resulting from transformation */
 77:   Mat              Op;               /* shell matrix for operator = alpha*D*inv(P)*M*inv(D) */
 78:   PetscBool        opseized;         /* whether Op has been seized by user */
 79:   PetscBool        opready;          /* whether Op is up-to-date or need be computed  */
 80:   Mat              P;                /* matrix from which preconditioner is built */
 81:   Mat              M;                /* matrix corresponding to the non-inverted part of the operator */
 82:   PetscBool        sigma_set;        /* whether the user provided the shift or not */
 83:   PetscBool        asymm;            /* the user matrices are all symmetric */
 84:   PetscBool        aherm;            /* the user matrices are all hermitian */
 85:   void             *data;
 86: };

 88: /*
 89:     Macros to test valid ST arguments
 90: */
 91: #if !defined(PETSC_USE_DEBUG)

 93: #define STCheckMatrices(h,arg) do {(void)(h);} while (0)
 94: #define STCheckNotSeized(h,arg) do {(void)(h);} while (0)

 96: #else

 98: #define STCheckMatrices(h,arg) \
 99:   do { \
100:     PetscCheck((h)->A,PetscObjectComm((PetscObject)(h)),PETSC_ERR_ARG_WRONGSTATE,"ST matrices have not been set: Parameter #%d",arg); \
101:   } while (0)
102: #define STCheckNotSeized(h,arg) \
103:   do { \
104:     PetscCheck(!(h)->opseized,PetscObjectComm((PetscObject)(h)),PETSC_ERR_ARG_WRONGSTATE,"Must call STRestoreOperator() first: Parameter #%d",arg); \
105:   } while (0)

107: #endif

109: SLEPC_INTERN PetscErrorCode STGetBilinearForm_Default(ST,Mat*);
110: SLEPC_INTERN PetscErrorCode STCheckNullSpace_Default(ST,BV);
111: SLEPC_INTERN PetscErrorCode STMatShellCreate(ST,PetscScalar,PetscInt,PetscInt*,PetscScalar*,Mat*);
112: SLEPC_INTERN PetscErrorCode STMatShellShift(Mat,PetscScalar);
113: SLEPC_INTERN PetscErrorCode STCheckFactorPackage(ST);
114: SLEPC_INTERN PetscErrorCode STMatMAXPY_Private(ST,PetscScalar,PetscScalar,PetscInt,PetscScalar*,PetscBool,PetscBool,Mat*);
115: SLEPC_INTERN PetscErrorCode STCoeffs_Monomial(ST,PetscScalar*);
116: SLEPC_INTERN PetscErrorCode STSetDefaultKSP(ST);
117: SLEPC_INTERN PetscErrorCode STSetDefaultKSP_Default(ST);
118: SLEPC_INTERN PetscErrorCode STIsInjective_Shell(ST,PetscBool*);
119: SLEPC_INTERN PetscErrorCode STComputeOperator(ST);
120: SLEPC_INTERN PetscErrorCode STGetOperator_Private(ST,Mat*);
121: SLEPC_INTERN PetscErrorCode STApply_Generic(ST,Vec,Vec);
122: SLEPC_INTERN PetscErrorCode STApplyMat_Generic(ST,Mat,Mat);
123: SLEPC_INTERN PetscErrorCode STApplyTranspose_Generic(ST,Vec,Vec);

125: /*
126:   ST_KSPSetOperators - Sets the KSP matrices
127: */
128: static inline PetscErrorCode ST_KSPSetOperators(ST st,Mat A,Mat B)
129: {
130:   const char     *prefix;

132:   PetscFunctionBegin;
133:   if (!st->ksp) PetscCall(STGetKSP(st,&st->ksp));
134:   PetscCall(STCheckFactorPackage(st));
135:   PetscCall(KSPSetOperators(st->ksp,A,B));
136:   PetscCall(MatGetOptionsPrefix(B,&prefix));
137:   if (!prefix) {
138:     /* set Mat prefix to be the same as KSP to enable setting command-line options (e.g. MUMPS)
139:        only applies if the Mat has no user-defined prefix */
140:     PetscCall(KSPGetOptionsPrefix(st->ksp,&prefix));
141:     PetscCall(MatSetOptionsPrefix(B,prefix));
142:   }
143:   PetscFunctionReturn(PETSC_SUCCESS);
144: }