LCOV - code coverage report
Current view: top level - home/gitlab-runner/builds/q8svuz_Y/0/slepc/slepc/include/slepc/private - mfnimpl.h (source / functions) Hit Total Coverage
Test: SLEPc Lines: 17 20 85.0 %
Date: 2024-05-01 00:51:33 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 <slepcmfn.h>
      14             : #include <slepc/private/slepcimpl.h>
      15             : 
      16             : /* SUBMANSEC = MFN */
      17             : 
      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;
      23             : 
      24             : typedef struct _MFNOps *MFNOps;
      25             : 
      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             : };
      35             : 
      36             : /*
      37             :      Maximum number of monitors you can run with a single MFN
      38             : */
      39             : #define MAXMFNMONITORS 5
      40             : 
      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 */
      53             : 
      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;
      59             : 
      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 */
      66             : 
      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             : };
      76             : 
      77             : /*
      78             :    MFN_CreateDenseMat - Creates a dense Mat of size k unless it already has that size
      79             : */
      80         237 : static inline PetscErrorCode MFN_CreateDenseMat(PetscInt k,Mat *A)
      81             : {
      82         237 :   PetscBool      create=PETSC_FALSE;
      83         237 :   PetscInt       m,n;
      84             : 
      85         237 :   PetscFunctionBegin;
      86         237 :   if (!*A) create=PETSC_TRUE;
      87             :   else {
      88           0 :     PetscCall(MatGetSize(*A,&m,&n));
      89           0 :     if (m!=k || n!=k) {
      90           0 :       PetscCall(MatDestroy(A));
      91             :       create=PETSC_TRUE;
      92             :     }
      93             :   }
      94         237 :   if (create) PetscCall(MatCreateSeqDense(PETSC_COMM_SELF,k,k,NULL,A));
      95         237 :   PetscFunctionReturn(PETSC_SUCCESS);
      96             : }
      97             : 
      98             : /*
      99             :    MFN_CreateVec - Creates a Vec of size k unless it already has that size
     100             : */
     101         221 : static inline PetscErrorCode MFN_CreateVec(PetscInt k,Vec *v)
     102             : {
     103         221 :   PetscBool      create=PETSC_FALSE;
     104         221 :   PetscInt       n;
     105             : 
     106         221 :   PetscFunctionBegin;
     107         221 :   if (!*v) create=PETSC_TRUE;
     108             :   else {
     109         128 :     PetscCall(VecGetSize(*v,&n));
     110         128 :     if (n!=k) {
     111         128 :       PetscCall(VecDestroy(v));
     112             :       create=PETSC_TRUE;
     113             :     }
     114             :   }
     115         221 :   if (create) PetscCall(VecCreateSeq(PETSC_COMM_SELF,k,v));
     116         221 :   PetscFunctionReturn(PETSC_SUCCESS);
     117             : }

Generated by: LCOV version 1.14