Date: 2023-01-26T12:19:38+00:00

Actual source code: mfnsetup.c
slepc-3.18.2 2023-01-26
Report Typos and Errors

      1: /*
      2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
      4:    Copyright (c) 2002-, Universitat Politecnica de Valencia, Spain

      6:    This file is part of SLEPc.
      7:    SLEPc is distributed under a 2-clause BSD license (see LICENSE).
      8:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      9: */
     10: /*
     11:    MFN routines related to problem setup
     12: */

     14: #include <slepc/private/mfnimpl.h>

     16: /*@
     17:    MFNSetUp - Sets up all the internal data structures necessary for the
     18:    execution of the matrix function solver.

     20:    Collective on mfn

     22:    Input Parameter:
     23: .  mfn   - matrix function context

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

     30:    Level: developer

     32: .seealso: MFNCreate(), MFNSolve(), MFNDestroy()
     33: @*/
     34: PetscErrorCode MFNSetUp(MFN mfn)
     35: {
     36:   PetscInt       N;

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

     43:   if (mfn->setupcalled) return 0;
     44:   PetscLogEventBegin(MFN_SetUp,mfn,0,0,0);

     46:   /* Set default solver type (MFNSetFromOptions was not called) */
     47:   if (!((PetscObject)mfn)->type_name) MFNSetType(mfn,MFNKRYLOV);
     48:   if (!mfn->fn) MFNGetFN(mfn,&mfn->fn);
     49:   if (!((PetscObject)mfn->fn)->type_name) FNSetFromOptions(mfn->fn);

     51:   /* Check problem dimensions */
     53:   MatGetSize(mfn->A,&N,NULL);
     54:   if (mfn->ncv > N) mfn->ncv = N;

     56:   /* call specific solver setup */
     57:   PetscUseTypeMethod(mfn,setup);

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

     62:   PetscLogEventEnd(MFN_SetUp,mfn,0,0,0);
     63:   mfn->setupcalled = 1;
     64:   return 0;
     65: }

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

     70:    Collective on mfn

     72:    Input Parameters:
     73: +  mfn - the matrix function context
     74: -  A   - the problem matrix

     76:    Notes:
     77:    It must be called before MFNSetUp(). If it is called again after MFNSetUp() then
     78:    the MFN object is reset.

     80:    Level: beginner

     82: .seealso: MFNSolve(), MFNSetUp(), MFNReset()
     83: @*/
     84: PetscErrorCode MFNSetOperator(MFN mfn,Mat A)
     85: {
     86:   PetscInt       m,n;

     92:   MatGetSize(A,&m,&n);
     94:   PetscObjectReference((PetscObject)A);
     95:   if (mfn->setupcalled) MFNReset(mfn);
     96:   else MatDestroy(&mfn->A);
     97:   mfn->A = A;
     98:   mfn->setupcalled = 0;
     99:   return 0;
    100: }

    102: /*@
    103:    MFNGetOperator - Gets the matrix associated with the MFN object.

    105:    Collective on mfn

    107:    Input Parameter:
    108: .  mfn - the MFN context

    110:    Output Parameters:
    111: .  A  - the matrix for which the matrix function is to be computed

    113:    Level: intermediate

    115: .seealso: MFNSolve(), MFNSetOperator()
    116: @*/
    117: PetscErrorCode MFNGetOperator(MFN mfn,Mat *A)
    118: {
    121:   *A = mfn->A;
    122:   return 0;
    123: }

    125: /*@
    126:    MFNAllocateSolution - Allocate memory storage for common variables such
    127:    as the basis vectors.

    129:    Collective on mfn

    131:    Input Parameters:
    132: +  mfn   - matrix function context
    133: -  extra - number of additional positions, used for methods that require a
    134:            working basis slightly larger than ncv

    136:    Developer Notes:
    137:    This is SLEPC_EXTERN because it may be required by user plugin MFN
    138:    implementations.

    140:    Level: developer

    142: .seealso: MFNSetUp()
    143: @*/
    144: PetscErrorCode MFNAllocateSolution(MFN mfn,PetscInt extra)
    145: {
    146:   PetscInt       oldsize,requested;
    147:   Vec            t;

    149:   requested = mfn->ncv + extra;

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

    154:   /* allocate basis vectors */
    155:   if (!mfn->V) MFNGetBV(mfn,&mfn->V);
    156:   if (!oldsize) {
    157:     if (!((PetscObject)(mfn->V))->type_name) BVSetType(mfn->V,BVSVEC);
    158:     MatCreateVecsEmpty(mfn->A,&t,NULL);
    159:     BVSetSizesFromVec(mfn->V,t,requested);
    160:     VecDestroy(&t);
    161:   } else BVResize(mfn->V,requested,PETSC_FALSE);
    162:   return 0;
    163: }