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

Actual source code: mfnsetup.c

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

      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/mfnimpl.h>       /*I "slepcmfn.h" I*/
     25: #include <slepc-private/ipimpl.h>

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

     33:    Collective on MFN

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

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

     43:    Level: advanced

     45: .seealso: MFNCreate(), MFNSolve(), MFNDestroy()
     46: @*/
     47: PetscErrorCode MFNSetUp(MFN mfn)
     48: {

     53:   if (mfn->setupcalled) return(0);
     54:   PetscLogEventBegin(MFN_SetUp,mfn,0,0,0);

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

     59:   /* Set default solver type (MFNSetFromOptions was not called) */
     60:   if (!((PetscObject)mfn)->type_name) {
     61:     MFNSetType(mfn,MFNKRYLOV);
     62:   }
     63:   if (!mfn->ip) { MFNGetIP(mfn,&mfn->ip); }
     64:   if (!((PetscObject)mfn->ip)->type_name) {
     65:     IPSetType_Default(mfn->ip);
     66:   }
     67:   IPSetMatrix(mfn->ip,NULL);
     68:   if (!mfn->ds) { MFNGetDS(mfn,&mfn->ds); }
     69:   DSReset(mfn->ds);
     70:   if (!((PetscObject)mfn->rand)->type_name) {
     71:     PetscRandomSetFromOptions(mfn->rand);
     72:   }

     74:   /* Set problem dimensions */
     75:   if (!mfn->A) SETERRQ(PetscObjectComm((PetscObject)mfn),PETSC_ERR_ARG_WRONGSTATE,"MFNSetOperator must be called first");
     76:   MatGetSize(mfn->A,&mfn->n,NULL);
     77:   MatGetLocalSize(mfn->A,&mfn->nloc,NULL);
     78:   VecDestroy(&mfn->t);
     79:   SlepcMatGetVecsTemplate(mfn->A,&mfn->t,NULL);
     80:   PetscLogObjectParent(mfn,mfn->t);

     82:   /* Set default function */
     83:   if (!mfn->function) {
     84:     MFNSetFunction(mfn,SLEPC_FUNCTION_EXP);
     85:   }

     87:   if (mfn->ncv > mfn->n) mfn->ncv = mfn->n;

     89:   /* call specific solver setup */
     90:   (*mfn->ops->setup)(mfn);

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

     95:   PetscLogEventEnd(MFN_SetUp,mfn,0,0,0);
     96:   mfn->setupcalled = 1;
     97:   return(0);
     98: }

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

    105:    Collective on MFN and Mat

    107:    Input Parameters:
    108: +  mfn - the matrix function context
    109: -  A   - the problem matrix

    111:    Notes:
    112:    It must be called after MFNSetUp(). If it is called again after MFNSetUp() then
    113:    the MFN object is reset.

    115:    Level: beginner

    117: .seealso: MFNSolve(), MFNSetUp(), MFNReset()
    118: @*/
    119: PetscErrorCode MFNSetOperator(MFN mfn,Mat A)
    120: {
    122:   PetscInt       m,n;

    129:   MatGetSize(A,&m,&n);
    130:   if (m!=n) SETERRQ(PetscObjectComm((PetscObject)mfn),PETSC_ERR_ARG_WRONG,"A is a non-square matrix");
    131:   if (mfn->setupcalled) { MFNReset(mfn); }
    132:   PetscObjectReference((PetscObject)A);
    133:   MatDestroy(&mfn->A);
    134:   mfn->A = A;
    135:   return(0);
    136: }

    140: /*@
    141:    MFNGetOperator - Gets the matrix associated with the MFN object.

    143:    Collective on MFN and Mat

    145:    Input Parameter:
    146: .  mfn - the MFN context

    148:    Output Parameters:
    149: .  A  - the matrix for which the matrix function is to be computed

    151:    Level: intermediate

    153: .seealso: MFNSolve(), MFNSetOperator()
    154: @*/
    155: PetscErrorCode MFNGetOperator(MFN mfn,Mat *A)
    156: {
    160:   *A = mfn->A;
    161:   return(0);
    162: }