Actual source code: slepcimpl.h

slepc-3.17.2 2022-08-09
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: */

 11: #if !defined(SLEPCIMPL_H)
 12: #define SLEPCIMPL_H

 14: #include <slepcsys.h>
 15: #include <petsc/private/petscimpl.h>

 17: SLEPC_INTERN PetscBool SlepcBeganPetsc;

 19: /*@C
 20:     SlepcHeaderCreate - Creates a SLEPc object

 22:     Input Parameters:
 23: +   classid - the classid associated with this object
 24: .   class_name - string name of class; should be static
 25: .   descr - string containing short description; should be static
 26: .   mansec - string indicating section in manual pages; should be static
 27: .   comm - the MPI Communicator
 28: .   destroy - the destroy routine for this object
 29: -   view - the view routine for this object

 31:     Output Parameter:
 32: .   h - the newly created object

 34:     Note:
 35:     This is equivalent to PetscHeaderCreate but makes sure that SlepcInitialize
 36:     has been called.

 38:     Level: developer
 39: @*/
 40: #define SlepcHeaderCreate(h,classid,class_name,descr,mansec,comm,destroy,view) \
 41:     ((!SlepcInitializeCalled && \
 42:     PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,1,PETSC_ERROR_INITIAL, \
 43:     "Must call SlepcInitialize instead of PetscInitialize to use SLEPc classes")) ||  \
 44:     PetscHeaderCreate(h,classid,class_name,descr,mansec,comm,destroy,view))

 46: /* context for monitors of type XXXMonitorConverged */
 47: struct _n_SlepcConvMon {
 48:   void     *ctx;
 49:   PetscInt oldnconv;  /* previous value of nconv */
 50: };

 52: /*
 53:   SlepcPrintEigenvalueASCII - Print an eigenvalue on an ASCII viewer.
 54: */
 55: static inline PetscErrorCode SlepcPrintEigenvalueASCII(PetscViewer viewer,PetscScalar eigr,PetscScalar eigi)
 56: {
 57:   PetscReal      re,im;

 59: #if defined(PETSC_USE_COMPLEX)
 60:   re = PetscRealPart(eigr);
 61:   im = PetscImaginaryPart(eigr);
 62: #else
 63:   re = eigr;
 64:   im = eigi;
 65: #endif
 66:   /* print zero instead of tiny value */
 67:   if (PetscAbs(im) && PetscAbs(re)/PetscAbs(im)<PETSC_SMALL) re = 0.0;
 68:   if (PetscAbs(re) && PetscAbs(im)/PetscAbs(re)<PETSC_SMALL) im = 0.0;
 69:   /* print as real if imaginary part is zero */
 70:   if (im!=0.0) PetscViewerASCIIPrintf(viewer,"%.5f%+.5fi",(double)re,(double)im);
 71:   else PetscViewerASCIIPrintf(viewer,"%.5f",(double)re);
 72:   PetscFunctionReturn(0);
 73: }

 75: /*
 76:   SlepcViewEigenvector - Outputs an eigenvector xr,xi to a viewer.
 77:   In complex scalars only xr is written.
 78:   The name of xr,xi is set before writing, based on the label, the index, and the name of obj.
 79: */
 80: static inline PetscErrorCode SlepcViewEigenvector(PetscViewer viewer,Vec xr,Vec xi,const char *label,PetscInt index,PetscObject obj)
 81: {
 82:   size_t         count;
 83:   char           vname[30];
 84:   const char     *pname;

 86:   PetscObjectGetName(obj,&pname);
 87:   PetscSNPrintfCount(vname,sizeof(vname),"%s%s",&count,label,PetscDefined(USE_COMPLEX)?"":"r");
 88:   count--;
 89:   PetscSNPrintf(vname+count,sizeof(vname)-count,"%" PetscInt_FMT "_%s",index,pname);
 90:   PetscObjectSetName((PetscObject)xr,vname);
 91:   VecView(xr,viewer);
 92: #if !defined(PETSC_USE_COMPLEX)
 93:   vname[count-1] = 'i';
 94:   PetscObjectSetName((PetscObject)xi,vname);
 95:   VecView(xi,viewer);
 96: #endif
 97:   PetscFunctionReturn(0);
 98: }

100: /* Macros for strings with different value in real and complex */
101: #if defined(PETSC_USE_COMPLEX)
102: #define SLEPC_STRING_HERMITIAN "hermitian"
103: #else
104: #define SLEPC_STRING_HERMITIAN "symmetric"
105: #endif

107: /* Private functions that are shared by several classes */
108: SLEPC_EXTERN PetscErrorCode SlepcBasisReference_Private(PetscInt,Vec*,PetscInt*,Vec**);
109: SLEPC_EXTERN PetscErrorCode SlepcBasisDestroy_Private(PetscInt*,Vec**);
110: SLEPC_EXTERN PetscErrorCode SlepcMonitorMakeKey_Internal(const char[],PetscViewerType,PetscViewerFormat,char[]);
111: SLEPC_EXTERN PetscErrorCode PetscViewerAndFormatCreate_Internal(PetscViewer,PetscViewerFormat,void*,PetscViewerAndFormat**);

113: SLEPC_INTERN PetscErrorCode SlepcCitationsInitialize(void);
114: SLEPC_INTERN PetscErrorCode SlepcInitialize_DynamicLibraries(void);
115: SLEPC_INTERN PetscErrorCode SlepcInitialize_Packages(void);

117: #endif