Actual source code: slepcimpl.h
slepc-3.16.2 2022-02-01
1: /*
2: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3: SLEPc - Scalable Library for Eigenvalue Problem Computations
4: Copyright (c) 2002-2021, 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: PETSC_STATIC_INLINE PetscErrorCode SlepcPrintEigenvalueASCII(PetscViewer viewer,PetscScalar eigr,PetscScalar eigi)
56: {
58: PetscReal re,im;
61: #if defined(PETSC_USE_COMPLEX)
62: re = PetscRealPart(eigr);
63: im = PetscImaginaryPart(eigr);
64: #else
65: re = eigr;
66: im = eigi;
67: #endif
68: /* print zero instead of tiny value */
69: if (PetscAbs(im) && PetscAbs(re)/PetscAbs(im)<PETSC_SMALL) re = 0.0;
70: if (PetscAbs(re) && PetscAbs(im)/PetscAbs(re)<PETSC_SMALL) im = 0.0;
71: /* print as real if imaginary part is zero */
72: if (im!=0.0) {
73: PetscViewerASCIIPrintf(viewer,"%.5f%+.5fi",(double)re,(double)im);
74: } else {
75: PetscViewerASCIIPrintf(viewer,"%.5f",(double)re);
76: }
77: return(0);
78: }
80: /*
81: SlepcViewEigenvector - Outputs an eigenvector xr,xi to a viewer.
82: In complex scalars only xr is written.
83: The name of xr,xi is set before writing, based on the label, the index, and the name of obj.
84: */
85: PETSC_STATIC_INLINE PetscErrorCode SlepcViewEigenvector(PetscViewer viewer,Vec xr,Vec xi,const char *label,PetscInt index,PetscObject obj)
86: {
88: size_t count;
89: char vname[30];
90: const char *pname;
93: PetscObjectGetName(obj,&pname);
94: PetscSNPrintfCount(vname,sizeof(vname),"%s%s",&count,label,PetscDefined(USE_COMPLEX)?"":"r");
95: count--;
96: PetscSNPrintf(vname+count,sizeof(vname)-count,"%d_%s",(int)index,pname);
97: PetscObjectSetName((PetscObject)xr,vname);
98: VecView(xr,viewer);
99: #if !defined(PETSC_USE_COMPLEX)
100: vname[count-1] = 'i';
101: PetscObjectSetName((PetscObject)xi,vname);
102: VecView(xi,viewer);
103: #endif
104: return(0);
105: }
107: /* Macros for strings with different value in real and complex */
108: #if defined(PETSC_USE_COMPLEX)
109: #define SLEPC_STRING_HERMITIAN "hermitian"
110: #else
111: #define SLEPC_STRING_HERMITIAN "symmetric"
112: #endif
114: /* Private functions that are shared by several classes */
115: SLEPC_EXTERN PetscErrorCode SlepcBasisReference_Private(PetscInt,Vec*,PetscInt*,Vec**);
116: SLEPC_EXTERN PetscErrorCode SlepcBasisDestroy_Private(PetscInt*,Vec**);
117: SLEPC_EXTERN PetscErrorCode SlepcMonitorMakeKey_Internal(const char[],PetscViewerType,PetscViewerFormat,char[]);
118: SLEPC_EXTERN PetscErrorCode PetscViewerAndFormatCreate_Internal(PetscViewer,PetscViewerFormat,void*,PetscViewerAndFormat**);
120: SLEPC_INTERN PetscErrorCode SlepcCitationsInitialize(void);
121: SLEPC_INTERN PetscErrorCode SlepcInitialize_DynamicLibraries(void);
122: SLEPC_INTERN PetscErrorCode SlepcInitialize_Packages(void);
124: #endif