Date: 2023-01-26T12:19:50+00:00

Actual source code: stimpl.h
slepc-3.18.2 2023-01-26
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: #if !defined(SLEPCSTIMPL_H)
     12: #define SLEPCSTIMPL_H

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

     17: /* SUBMANSEC = ST */

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

     23: typedef struct _STOps *STOps;

     25: struct _STOps {
     26:   PetscErrorCode (*apply)(ST,Vec,Vec);
     27:   PetscErrorCode (*applymat)(ST,Mat,Mat);
     28:   PetscErrorCode (*applytrans)(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: };

     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;

     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:   Vec              D;                /* diagonal matrix for balancing */
     62:   Mat              Pmat;             /* user-provided preconditioner matrix */
     63:   PetscBool        Pmat_set;         /* whether the user provided a preconditioner matrix or not  */
     64:   Mat              *Psplit;          /* matrices for the split preconditioner */
     65:   PetscInt         nsplit;           /* number of split preconditioner matrices */
     66:   MatStructure     strp;             /* pattern of split preconditioner matrices */

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

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

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

     97: #else

     99: #define STCheckMatrices(h,arg) \
    100:   do { \
    102:   } while (0)
    103: #define STCheckNotSeized(h,arg) \
    104:   do { \
    106:   } while (0)

    108: #endif

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

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

    133:   if (!st->ksp) STGetKSP(st,&st->ksp);
    134:   STCheckFactorPackage(st);
    135:   KSPSetOperators(st->ksp,A,B);
    136:   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:     KSPGetOptionsPrefix(st->ksp,&prefix);
    141:     MatSetOptionsPrefix(B,prefix);
    142:   }
    143:   return 0;
    144: }

    146: #endif