Actual source code: mfnimpl.h

slepc-main 2023-10-18
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 <slepcmfn.h>
 14: #include <slepc/private/slepcimpl.h>

 16: /* SUBMANSEC = MFN */

 18: SLEPC_EXTERN PetscBool MFNRegisterAllCalled;
 19: SLEPC_EXTERN PetscBool MFNMonitorRegisterAllCalled;
 20: SLEPC_EXTERN PetscErrorCode MFNRegisterAll(void);
 21: SLEPC_EXTERN PetscErrorCode MFNMonitorRegisterAll(void);
 22: SLEPC_EXTERN PetscLogEvent MFN_SetUp,MFN_Solve;

 24: typedef struct _MFNOps *MFNOps;

 26: struct _MFNOps {
 27:   PetscErrorCode (*solve)(MFN,Vec,Vec);
 28:   PetscErrorCode (*setup)(MFN);
 29:   PetscErrorCode (*setfromoptions)(MFN,PetscOptionItems*);
 30:   PetscErrorCode (*publishoptions)(MFN);
 31:   PetscErrorCode (*destroy)(MFN);
 32:   PetscErrorCode (*reset)(MFN);
 33:   PetscErrorCode (*view)(MFN,PetscViewer);
 34: };

 36: /*
 37:      Maximum number of monitors you can run with a single MFN
 38: */
 39: #define MAXMFNMONITORS 5

 41: /*
 42:    Defines the MFN data structure.
 43: */
 44: struct _p_MFN {
 45:   PETSCHEADER(struct _MFNOps);
 46:   /*------------------------- User parameters ---------------------------*/
 47:   Mat            A;                /* the problem matrix */
 48:   FN             fn;               /* which function to compute */
 49:   PetscInt       max_it;           /* maximum number of iterations */
 50:   PetscInt       ncv;              /* number of basis vectors */
 51:   PetscReal      tol;              /* tolerance */
 52:   PetscBool      errorifnotconverged;    /* error out if MFNSolve() does not converge */

 54:   /*-------------- User-provided functions and contexts -----------------*/
 55:   PetscErrorCode (*monitor[MAXMFNMONITORS])(MFN,PetscInt,PetscReal,void*);
 56:   PetscErrorCode (*monitordestroy[MAXMFNMONITORS])(void**);
 57:   void           *monitorcontext[MAXMFNMONITORS];
 58:   PetscInt       numbermonitors;

 60:   /*----------------- Child objects and working data -------------------*/
 61:   BV             V;                /* set of basis vectors */
 62:   Mat            AT;               /* the transpose of A, used in MFNSolveTranspose */
 63:   PetscInt       nwork;            /* number of work vectors */
 64:   Vec            *work;            /* work vectors */
 65:   void           *data;            /* placeholder for solver-specific stuff */

 67:   /* ----------------------- Status variables -------------------------- */
 68:   PetscInt       its;              /* number of iterations so far computed */
 69:   PetscInt       nv;               /* size of current Schur decomposition */
 70:   PetscReal      errest;           /* error estimate */
 71:   PetscReal      bnorm;            /* computed norm of right-hand side in current solve */
 72:   PetscBool      transpose_solve;  /* solve transpose system instead */
 73:   PetscInt       setupcalled;
 74:   MFNConvergedReason reason;
 75: };

 77: /*
 78:    MFN_CreateDenseMat - Creates a dense Mat of size k unless it already has that size
 79: */
 80: static inline PetscErrorCode MFN_CreateDenseMat(PetscInt k,Mat *A)
 81: {
 82:   PetscBool      create=PETSC_FALSE;
 83:   PetscInt       m,n;

 85:   PetscFunctionBegin;
 86:   if (!*A) create=PETSC_TRUE;
 87:   else {
 88:     PetscCall(MatGetSize(*A,&m,&n));
 89:     if (m!=k || n!=k) {
 90:       PetscCall(MatDestroy(A));
 91:       create=PETSC_TRUE;
 92:     }
 93:   }
 94:   if (create) PetscCall(MatCreateSeqDense(PETSC_COMM_SELF,k,k,NULL,A));
 95:   PetscFunctionReturn(PETSC_SUCCESS);
 96: }

 98: /*
 99:    MFN_CreateVec - Creates a Vec of size k unless it already has that size
100: */
101: static inline PetscErrorCode MFN_CreateVec(PetscInt k,Vec *v)
102: {
103:   PetscBool      create=PETSC_FALSE;
104:   PetscInt       n;

106:   PetscFunctionBegin;
107:   if (!*v) create=PETSC_TRUE;
108:   else {
109:     PetscCall(VecGetSize(*v,&n));
110:     if (n!=k) {
111:       PetscCall(VecDestroy(v));
112:       create=PETSC_TRUE;
113:     }
114:   }
115:   if (create) PetscCall(VecCreateSeq(PETSC_COMM_SELF,k,v));
116:   PetscFunctionReturn(PETSC_SUCCESS);
117: }