LCOV - code coverage report
Current view: top level - pep/impls - peputils.c (source / functions) Hit Total Coverage
Test: SLEPc Lines: 49 49 100.0 %
Date: 2024-04-27 00:39:19 Functions: 3 3 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             :    Common subroutines for several PEP solvers
      12             : */
      13             : 
      14             : #include <slepc/private/pepimpl.h>    /*I "slepcpep.h" I*/
      15             : #include <slepcblaslapack.h>
      16             : 
      17             : /*
      18             :   Computes T_j=phy_idx(T) for a matrix T.
      19             :     Tp (if j>0) and Tpp (if j>1) are the evaluation
      20             :     of phy_(j-1) and phy(j-2)respectively.
      21             : */
      22          62 : PetscErrorCode PEPEvaluateBasisMat(PEP pep,PetscInt k,PetscScalar *T,PetscInt ldt,PetscInt idx,PetscScalar *Tpp,PetscInt ldtpp,PetscScalar *Tp,PetscInt ldtp,PetscScalar *Tj,PetscInt ldtj)
      23             : {
      24          62 :   PetscInt       i;
      25          62 :   PetscReal      *ca,*cb,*cg;
      26          62 :   PetscScalar    g,a;
      27          62 :   PetscBLASInt   k_,ldt_,ldtj_,ldtp_;
      28             : 
      29          62 :   PetscFunctionBegin;
      30          62 :   if (idx==0) {
      31          55 :     for (i=0;i<k;i++) {
      32          35 :       PetscCall(PetscArrayzero(Tj+i*ldtj,k));
      33          35 :       Tj[i+i*ldtj] = 1.0;
      34             :     }
      35             :   } else {
      36          42 :     PetscCall(PetscBLASIntCast(ldt,&ldt_));
      37          42 :     PetscCall(PetscBLASIntCast(ldtj,&ldtj_));
      38          42 :     PetscCall(PetscBLASIntCast(ldtp,&ldtp_));
      39          42 :     PetscCall(PetscBLASIntCast(k,&k_));
      40          42 :     ca = pep->pbc; cb = pep->pbc+pep->nmat; cg = pep->pbc+2*pep->nmat;
      41         114 :     for (i=0;i<k;i++) T[i*ldt+i] -= cb[idx-1];
      42          42 :     if (idx>1) {
      43          59 :       for (i=0;i<k;i++) PetscCall(PetscArraycpy(Tj+i*ldtj,Tpp+i*ldtpp,k));
      44             :     }
      45          42 :     a = 1/ca[idx-1];
      46          42 :     g = (idx==1)?0.0:-cg[idx-1]/ca[idx-1];
      47          42 :     PetscCallBLAS("BLASgemm",BLASgemm_("N","N",&k_,&k_,&k_,&a,T,&ldt_,Tp,&ldtp_,&g,Tj,&ldtj_));
      48         114 :     for (i=0;i<k;i++) T[i*ldt+i] += cb[idx-1];
      49             :   }
      50          62 :   PetscFunctionReturn(PETSC_SUCCESS);
      51             : }
      52             : 
      53             : /*
      54             :    PEPEvaluateBasis - evaluate the polynomial basis on a given parameter sigma
      55             : */
      56        5646 : PetscErrorCode PEPEvaluateBasis(PEP pep,PetscScalar sigma,PetscScalar isigma,PetscScalar *vals,PetscScalar *ivals)
      57             : {
      58        5646 :   PetscInt   nmat=pep->nmat,k;
      59        5646 :   PetscReal  *a=pep->pbc,*b=pep->pbc+nmat,*g=pep->pbc+2*nmat;
      60             : 
      61        5646 :   PetscFunctionBegin;
      62       17231 :   if (ivals) for (k=0;k<nmat;k++) ivals[k] = 0.0;
      63        5646 :   vals[0] = 1.0;
      64        5646 :   vals[1] = (sigma-b[0])/a[0];
      65             : #if !defined(PETSC_USE_COMPLEX)
      66             :   if (ivals) ivals[1] = isigma/a[0];
      67             : #endif
      68       14687 :   for (k=2;k<nmat;k++) {
      69        9041 :     vals[k] = ((sigma-b[k-1])*vals[k-1]-g[k-1]*vals[k-2])/a[k-1];
      70        9041 :     if (ivals) vals[k] -= isigma*ivals[k-1]/a[k-1];
      71             : #if !defined(PETSC_USE_COMPLEX)
      72             :     if (ivals) ivals[k] = ((sigma-b[k-1])*ivals[k-1]+isigma*vals[k-1]-g[k-1]*ivals[k-2])/a[k-1];
      73             : #endif
      74             :   }
      75        5646 :   PetscFunctionReturn(PETSC_SUCCESS);
      76             : }
      77             : 
      78             : /*
      79             :    PEPEvaluateBasisDerivative - evaluate the derivative of the polynomial basis on a given parameter sigma
      80             : */
      81         770 : PetscErrorCode PEPEvaluateBasisDerivative(PEP pep,PetscScalar sigma,PetscScalar isigma,PetscScalar *vals,PetscScalar *ivals)
      82             : {
      83         770 :   PetscInt       nmat=pep->nmat,k;
      84         770 :   PetscReal      *a=pep->pbc,*b=pep->pbc+nmat,*g=pep->pbc+2*nmat;
      85             : 
      86         770 :   PetscFunctionBegin;
      87         770 :   PetscCall(PEPEvaluateBasis(pep,sigma,isigma,vals,ivals));
      88        3060 :   for (k=nmat-1;k>0;k--) {
      89        2290 :     vals[k] = vals[k-1];
      90        2290 :     if (ivals) ivals[k] = ivals[k-1];
      91             :   }
      92         770 :   vals[0] = 0.0;
      93         770 :   vals[1] = vals[1]/a[0];
      94             : #if !defined(PETSC_USE_COMPLEX)
      95             :   if (ivals) ivals[1] = ivals[1]/a[0];
      96             : #endif
      97        2290 :   for (k=2;k<nmat;k++) {
      98        1520 :     vals[k] += (sigma-b[k-1])*vals[k-1]-g[k-1]*vals[k-2];
      99        1520 :     if (ivals) vals[k] -= isigma*ivals[k-1];
     100        1520 :     vals[k] /= a[k-1];
     101             : #if !defined(PETSC_USE_COMPLEX)
     102             :     if (ivals) {
     103             :       ivals[k] += (sigma-b[k-1])*ivals[k-1]+isigma*vals[k-1]-g[k-1]*ivals[k-2];
     104             :       ivals[k] /= a[k-1];
     105             :     }
     106             : #endif
     107             :   }
     108         770 :   PetscFunctionReturn(PETSC_SUCCESS);
     109             : }

Generated by: LCOV version 1.14