Date: 2022-03-31T15:29:42+00:00

Actual source code: mfnimpl.h
slepc-3.17.0 2022-03-31
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(SLEPCMFNIMPL_H)
     12: #define SLEPCMFNIMPL_H

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

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

     23: typedef struct _MFNOps *MFNOps;

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

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

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

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

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

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

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

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

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

    104:   if (!*v) create=PETSC_TRUE;
    105:   else {
    106:     VecGetSize(*v,&n);
    107:     if (n!=k) {
    108:       VecDestroy(v);
    109:       create=PETSC_TRUE;
    110:     }
    111:   }
    112:   if (create) VecCreateSeq(PETSC_COMM_SELF,k,v);
    113:   PetscFunctionReturn(0);
    114: }

    116: #endif