LCOV - code coverage report
Current view: top level - eps/impls/davidson - dvdinitv.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 61 64 95.3 %
Date: 2019-10-20 05:41:02 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /*
       2             :    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       3             :    SLEPc - Scalable Library for Eigenvalue Problem Computations
       4             :    Copyright (c) 2002-2019, 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             :    SLEPc eigensolver: "davidson"
      12             : 
      13             :    Step: initialize subspace V
      14             : */
      15             : 
      16             : #include "davidson.h"
      17             : 
      18             : typedef struct {
      19             :   PetscInt k;                 /* desired initial subspace size */
      20             :   PetscInt user;              /* number of user initial vectors */
      21             :   void     *old_initV_data;   /* old initV data */
      22             : } dvdInitV;
      23             : 
      24          80 : static PetscErrorCode dvd_initV_classic_0(dvdDashboard *d)
      25             : {
      26             :   PetscErrorCode ierr;
      27          80 :   dvdInitV       *data = (dvdInitV*)d->initV_data;
      28          80 :   PetscInt       i,user = PetscMin(data->user,d->eps->mpd), l,k;
      29             : 
      30          80 :   PetscFunctionBegin;
      31          80 :   ierr = BVGetActiveColumns(d->eps->V,&l,&k);CHKERRQ(ierr);
      32             :   /* User vectors are added at the beginning, so no active column should be in V */
      33          80 :   if (data->user>0&&l>0) SETERRQ(PETSC_COMM_SELF,1,"Consistency broken");
      34             :   /* Generate a set of random initial vectors and orthonormalize them */
      35         543 :   for (i=l+user;i<l+data->k && i<d->eps->ncv && i-l<d->eps->mpd;i++) {
      36         463 :     ierr = BVSetRandomColumn(d->eps->V,i);CHKERRQ(ierr);
      37             :   }
      38          80 :   d->V_tra_s = 0; d->V_tra_e = 0;
      39          80 :   d->V_new_s = 0; d->V_new_e = i-l;
      40             : 
      41             :   /* After that the user vectors will be destroyed */
      42          80 :   data->user = 0;
      43          80 :   PetscFunctionReturn(0);
      44             : }
      45             : 
      46          10 : static PetscErrorCode dvd_initV_krylov_0(dvdDashboard *d)
      47             : {
      48             :   PetscErrorCode ierr;
      49          10 :   dvdInitV       *data = (dvdInitV*)d->initV_data;
      50          10 :   PetscInt       i,user = PetscMin(data->user,d->eps->mpd),l,k;
      51             :   Vec            av,v1,v2;
      52             : 
      53          10 :   PetscFunctionBegin;
      54          10 :   ierr = BVGetActiveColumns(d->eps->V,&l,&k);CHKERRQ(ierr);
      55             :   /* User vectors are added at the beginning, so no active column should be in V */
      56          10 :   if (data->user>0&&l>0) SETERRQ(PETSC_COMM_SELF,1,"Consistency broken");
      57             : 
      58             :   /* If needed, generate a random vector for starting the arnoldi method */
      59          10 :   if (user == 0) {
      60           9 :     ierr = BVSetRandomColumn(d->eps->V,l);CHKERRQ(ierr);
      61             :     user = 1;
      62             :   }
      63             : 
      64             :   /* Perform k steps of Arnoldi with the operator K^{-1}*(t[1]*A-t[2]*B) */
      65          10 :   ierr = dvd_orthV(d->eps->V,l,l+user);CHKERRQ(ierr);
      66          70 :   for (i=l+user;i<l+data->k && i<d->eps->ncv && i-l<d->eps->mpd;i++) {
      67             :     /* aux <- theta[1]A*in - theta[0]*B*in */
      68          50 :     ierr = BVGetColumn(d->eps->V,i,&v1);CHKERRQ(ierr);
      69          50 :     ierr = BVGetColumn(d->eps->V,i-user,&v2);CHKERRQ(ierr);
      70          50 :     ierr = BVGetColumn(d->auxBV,0,&av);CHKERRQ(ierr);
      71          50 :     if (d->B) {
      72           0 :       ierr = MatMult(d->A,v2,v1);CHKERRQ(ierr);
      73           0 :       ierr = MatMult(d->B,v2,av);CHKERRQ(ierr);
      74           0 :       ierr = VecAXPBY(av,d->target[1],-d->target[0],v1);CHKERRQ(ierr);
      75             :     } else {
      76          50 :       ierr = MatMult(d->A,v2,av);CHKERRQ(ierr);
      77          50 :       ierr = VecAXPBY(av,-d->target[0],d->target[1],v2);CHKERRQ(ierr);
      78             :     }
      79          50 :     ierr = d->improvex_precond(d,0,av,v1);CHKERRQ(ierr);
      80          50 :     ierr = BVRestoreColumn(d->eps->V,i,&v1);CHKERRQ(ierr);
      81          50 :     ierr = BVRestoreColumn(d->eps->V,i-user,&v2);CHKERRQ(ierr);
      82          50 :     ierr = BVRestoreColumn(d->auxBV,0,&av);CHKERRQ(ierr);
      83          50 :     ierr = dvd_orthV(d->eps->V,i,i+1);CHKERRQ(ierr);
      84             :   }
      85             : 
      86          10 :   d->V_tra_s = 0; d->V_tra_e = 0;
      87          10 :   d->V_new_s = 0; d->V_new_e = i-l;
      88             : 
      89             :   /* After that the user vectors will be destroyed */
      90          10 :   data->user = 0;
      91          10 :   PetscFunctionReturn(0);
      92             : }
      93             : 
      94          90 : static PetscErrorCode dvd_initV_d(dvdDashboard *d)
      95             : {
      96             :   PetscErrorCode ierr;
      97          90 :   dvdInitV       *data = (dvdInitV*)d->initV_data;
      98             : 
      99          90 :   PetscFunctionBegin;
     100             :   /* Restore changes in dvdDashboard */
     101          90 :   d->initV_data = data->old_initV_data;
     102             : 
     103             :   /* Free local data */
     104          90 :   ierr = PetscFree(data);CHKERRQ(ierr);
     105          90 :   PetscFunctionReturn(0);
     106             : }
     107             : 
     108         270 : PetscErrorCode dvd_initV(dvdDashboard *d, dvdBlackboard *b, PetscInt k,PetscInt user, PetscBool krylov)
     109             : {
     110             :   PetscErrorCode ierr;
     111             :   dvdInitV       *data;
     112             : 
     113         270 :   PetscFunctionBegin;
     114             :   /* Setting configuration constrains */
     115         270 :   b->max_size_V = PetscMax(b->max_size_V, k);
     116             : 
     117             :   /* Setup the step */
     118         270 :   if (b->state >= DVD_STATE_CONF) {
     119          90 :     ierr = PetscNewLog(d->eps,&data);CHKERRQ(ierr);
     120          90 :     data->k = k;
     121          90 :     data->user = user;
     122          90 :     data->old_initV_data = d->initV_data;
     123          90 :     d->initV_data = data;
     124          90 :     if (krylov) d->initV = dvd_initV_krylov_0;
     125          80 :     else d->initV = dvd_initV_classic_0;
     126          90 :     ierr = EPSDavidsonFLAdd(&d->destroyList,dvd_initV_d);CHKERRQ(ierr);
     127             :   }
     128         270 :   PetscFunctionReturn(0);
     129             : }
     130             : 
     131        8464 : PetscErrorCode dvd_orthV(BV V,PetscInt V_new_s,PetscInt V_new_e)
     132             : {
     133             :   PetscErrorCode ierr;
     134             :   PetscInt       i;
     135             : 
     136        8464 :   PetscFunctionBegin;
     137       12473 :   for (i=V_new_s;i<V_new_e;i++) {
     138       12473 :     ierr = BVOrthonormalizeColumn(V,i,PETSC_TRUE,NULL,NULL);CHKERRQ(ierr);
     139             :   }
     140        8464 :   PetscFunctionReturn(0);
     141             : }
     142             : 

Generated by: LCOV version 1.13