Date: 2013-09-02T10:08:40+00:00

Actual source code: ipform.c

      1: /*
      2:      Routines for setting the matrix representation of the inner product.

      4:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      5:    SLEPc - Scalable Library for Eigenvalue Problem Computations
      6:    Copyright (c) 2002-2013, Universitat Politecnica de Valencia, Spain

      8:    This file is part of SLEPc.

     10:    SLEPc is free software: you can redistribute it and/or modify it under  the
     11:    terms of version 3 of the GNU Lesser General Public License as published by
     12:    the Free Software Foundation.

     14:    SLEPc  is  distributed in the hope that it will be useful, but WITHOUT  ANY
     15:    WARRANTY;  without even the implied warranty of MERCHANTABILITY or  FITNESS
     16:    FOR  A  PARTICULAR PURPOSE. See the GNU Lesser General Public  License  for
     17:    more details.

     19:    You  should have received a copy of the GNU Lesser General  Public  License
     20:    along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
     21:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     22: */

     24: #include <slepc-private/ipimpl.h>      /*I "slepcip.h" I*/

     28: /*@
     29:    IPSetMatrix - Specifies the matrix representation of the inner product.

     31:    Collective on IP

     33:    Input Parameters:
     34: +  ip    - the inner product context
     35: -  mat   - the matrix (may be NULL)

     37:    Notes:
     38:    A NULL has the same effect as if the identity matrix was passed.

     40:    This function is called by EPSSetProblemType() and usually need not be
     41:    called by the user.

     43:    Level: developer

     45: .seealso: IPGetMatrix(), IPInnerProduct(), IPNorm(), EPSSetProblemType()
     46: @*/
     47: PetscErrorCode IPSetMatrix(IP ip,Mat mat)
     48: {

     53:   if (mat) {
     55:     PetscObjectReference((PetscObject)mat);
     56:   }
     57:   IPReset(ip);
     58:   ip->matrix = mat;
     59:   if (mat) {
     60:     MatGetVecs(mat,&ip->Bx,NULL);
     61:     PetscLogObjectParent(ip,ip->Bx);
     62:   }
     63:   return(0);
     64: }

     68: /*@C
     69:    IPGetMatrix - Retrieves the matrix representation of the inner product.

     71:    Not collective, though a parallel Mat may be returned

     73:    Input Parameter:
     74: .  ip    - the inner product context

     76:    Output Parameter:
     77: .  mat   - the matrix of the inner product (may be NULL)

     79:    Level: developer

     81: .seealso: IPSetMatrix(), IPInnerProduct(), IPNorm(), EPSSetProblemType()
     82: @*/
     83: PetscErrorCode IPGetMatrix(IP ip,Mat* mat)
     84: {
     88:   *mat  = ip->matrix;
     89:   return(0);
     90: }

     94: PetscErrorCode IPApplyMatrix_Private(IP ip,Vec x)
     95: {

     99:   if (((PetscObject)x)->id != ip->xid || ((PetscObject)x)->state != ip->xstate) {
    100:     PetscLogEventBegin(IP_ApplyMatrix,ip,0,0,0);
    101:     MatMult(ip->matrix,x,ip->Bx);
    102:     ip->xid = ((PetscObject)x)->id;
    103:     ip->xstate = ((PetscObject)x)->state;
    104:     PetscLogEventEnd(IP_ApplyMatrix,ip,0,0,0);
    105:   }
    106:   return(0);
    107: }

    111: /*@
    112:    IPApplyMatrix - Multiplies a vector by the matrix representing the IP.

    114:    Neighbor-wise Collective on IP and Vec

    116:    Input Parameters:
    117: +  ip    - the inner product context
    118: -  x     - the vector

    120:    Output Parameter:
    121: .  y     - the result

    123:    Note:
    124:    If no matrix was specified this function copies the vector.

    126:    Level: developer

    128: .seealso: IPSetMatrix(), IPInnerProduct(), IPNorm(), EPSSetProblemType()
    129: @*/
    130: PetscErrorCode IPApplyMatrix(IP ip,Vec x,Vec y)
    131: {

    136:   if (ip->matrix) {
    137:     IPApplyMatrix_Private(ip,x);
    138:     VecCopy(ip->Bx,y);
    139:   } else {
    140:     VecCopy(x,y);
    141:   }
    142:   return(0);
    143: }