Date: 2015-09-03T15:06:07+00:00

Actual source code: mfnsetup.c
slepc-3.6.1 2015-09-03
Report Typos and Errors

      1: /*
      2:       MFN routines related to problem setup.

      4:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      5:    SLEPc - Scalable Library for Eigenvalue Problem Computations
      6:    Copyright (c) 2002-2015, 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/mfnimpl.h>       /*I "slepcmfn.h" I*/

     28: /*@
     29:    MFNSetUp - Sets up all the internal data structures necessary for the
     30:    execution of the matrix function solver.

     32:    Collective on MFN

     34:    Input Parameter:
     35: .  mfn   - matrix function context

     37:    Notes:
     38:    This function need not be called explicitly in most cases, since MFNSolve()
     39:    calls it. It can be useful when one wants to measure the set-up time
     40:    separately from the solve time.

     42:    Level: developer

     44: .seealso: MFNCreate(), MFNSolve(), MFNDestroy()
     45: @*/
     46: PetscErrorCode MFNSetUp(MFN mfn)
     47: {
     49:   PetscInt       N;

     54:   /* reset the convergence flag from the previous solves */
     55:   mfn->reason = MFN_CONVERGED_ITERATING;

     57:   if (mfn->setupcalled) return(0);
     58:   PetscLogEventBegin(MFN_SetUp,mfn,0,0,0);

     60:   /* Set default solver type (MFNSetFromOptions was not called) */
     61:   if (!((PetscObject)mfn)->type_name) {
     62:     MFNSetType(mfn,MFNKRYLOV);
     63:   }
     64:   if (!mfn->fn) { MFNGetFN(mfn,&mfn->fn); }
     65:   if (!((PetscObject)mfn->fn)->type_name) {
     66:     FNSetFromOptions(mfn->fn);
     67:   }
     68:   if (!((PetscObject)mfn->rand)->type_name) {
     69:     PetscRandomSetFromOptions(mfn->rand);
     70:   }

     72:   /* Check problem dimensions */
     73:   if (!mfn->A) SETERRQ(PetscObjectComm((PetscObject)mfn),PETSC_ERR_ARG_WRONGSTATE,"MFNSetOperator must be called first");
     74:   MatGetSize(mfn->A,&N,NULL);
     75:   if (mfn->ncv > N) mfn->ncv = N;

     77:   /* call specific solver setup */
     78:   (*mfn->ops->setup)(mfn);

     80:   /* set tolerance if not yet set */
     81:   if (mfn->tol==PETSC_DEFAULT) mfn->tol = SLEPC_DEFAULT_TOL;

     83:   PetscLogEventEnd(MFN_SetUp,mfn,0,0,0);
     84:   mfn->setupcalled = 1;
     85:   return(0);
     86: }

     90: /*@
     91:    MFNSetOperator - Sets the matrix for which the matrix function is to be computed.

     93:    Collective on MFN and Mat

     95:    Input Parameters:
     96: +  mfn - the matrix function context
     97: -  A   - the problem matrix

     99:    Notes:
    100:    It must be called before MFNSetUp(). If it is called again after MFNSetUp() then
    101:    the MFN object is reset.

    103:    Level: beginner

    105: .seealso: MFNSolve(), MFNSetUp(), MFNReset()
    106: @*/
    107: PetscErrorCode MFNSetOperator(MFN mfn,Mat A)
    108: {
    110:   PetscInt       m,n;

    117:   MatGetSize(A,&m,&n);
    118:   if (m!=n) SETERRQ(PetscObjectComm((PetscObject)mfn),PETSC_ERR_ARG_WRONG,"A is a non-square matrix");
    119:   if (mfn->setupcalled) { MFNReset(mfn); }
    120:   PetscObjectReference((PetscObject)A);
    121:   MatDestroy(&mfn->A);
    122:   mfn->A = A;
    123:   return(0);
    124: }

    128: /*@
    129:    MFNGetOperator - Gets the matrix associated with the MFN object.

    131:    Collective on MFN and Mat

    133:    Input Parameter:
    134: .  mfn - the MFN context

    136:    Output Parameters:
    137: .  A  - the matrix for which the matrix function is to be computed

    139:    Level: intermediate

    141: .seealso: MFNSolve(), MFNSetOperator()
    142: @*/
    143: PetscErrorCode MFNGetOperator(MFN mfn,Mat *A)
    144: {
    148:   *A = mfn->A;
    149:   return(0);
    150: }

    154: /*@
    155:    MFNAllocateSolution - Allocate memory storage for common variables such
    156:    as the basis vectors.

    158:    Collective on MFN

    160:    Input Parameters:
    161: +  mfn   - eigensolver context
    162: -  extra - number of additional positions, used for methods that require a
    163:            working basis slightly larger than ncv

    165:    Developers Note:
    166:    This is PETSC_EXTERN because it may be required by user plugin MFN
    167:    implementations.

    169:    Level: developer
    170: @*/
    171: PetscErrorCode MFNAllocateSolution(MFN mfn,PetscInt extra)
    172: {
    174:   PetscInt       oldsize,requested;
    175:   Vec            t;

    178:   requested = mfn->ncv + extra;

    180:   /* oldsize is zero if this is the first time setup is called */
    181:   BVGetSizes(mfn->V,NULL,NULL,&oldsize);

    183:   /* allocate basis vectors */
    184:   if (!mfn->V) { MFNGetBV(mfn,&mfn->V); }
    185:   if (!oldsize) {
    186:     if (!((PetscObject)(mfn->V))->type_name) {
    187:       BVSetType(mfn->V,BVSVEC);
    188:     }
    189:     MatCreateVecs(mfn->A,&t,NULL);
    190:     BVSetSizesFromVec(mfn->V,t,requested);
    191:     VecDestroy(&t);
    192:   } else {
    193:     BVResize(mfn->V,requested,PETSC_FALSE);
    194:   }
    195:   return(0);
    196: }