Fast Auxiliary Space Preconditioning 2.7.7 Aug/28/2022
Loading...
Searching...
No Matches
BlaEigen.c
Go to the documentation of this file.
1
14#include <math.h>
15
16#include "fasp.h"
17#include "fasp_functs.h"
18
19/*---------------------------------*/
20/*-- Public Functions --*/
21/*---------------------------------*/
22
38 const REAL tol,
39 const INT maxit)
40{
41 REAL eigenvalue = 0.0, temp = 1.0, L2_norm_y;
42 dvector x, y;
43 int i;
44
45 fasp_dvec_alloc(A->row, &x);
46 fasp_dvec_rand(A->row,&x);
48
49 fasp_dvec_alloc(A->row, &y);
50
51 for ( i = maxit; i--; ) {
52 // y = Ax;
53 fasp_blas_dcsr_mxv(A, x.val, y.val);
54
55 // y/||y||
56 L2_norm_y = fasp_blas_dvec_norm2(&y);
57 fasp_blas_darray_ax(A->row, 1.0/L2_norm_y, y.val);
58
59 // eigenvalue = y'Ay;
60 eigenvalue = fasp_blas_dcsr_vmv(A, y.val, y.val);
61
62 // convergence test
63 if ( (ABS(eigenvalue - temp)/ABS(temp)) < tol ) break;
64
65 fasp_dvec_cp(&y, &x);
66 temp = eigenvalue;
67 }
68
69 // clean up memory
72
73 return eigenvalue;
74}
75
76/*---------------------------------*/
77/*-- End of File --*/
78/*---------------------------------*/
void fasp_dvec_free(dvector *u)
Free vector data space of REAL type.
Definition: AuxVector.c:145
void fasp_dvec_rand(const INT n, dvector *x)
Generate fake random REAL vector in the range from 0 to 1.
Definition: AuxVector.c:192
void fasp_dvec_alloc(const INT m, dvector *u)
Create dvector data space of REAL type.
Definition: AuxVector.c:105
void fasp_dvec_cp(const dvector *x, dvector *y)
Copy dvector x to dvector y.
Definition: AuxVector.c:334
void fasp_blas_darray_ax(const INT n, const REAL a, REAL *x)
x = a*x
Definition: BlaArray.c:43
REAL fasp_dcsr_maxeig(const dCSRmat *A, const REAL tol, const INT maxit)
Approximate the largest eigenvalue of A by the power method.
Definition: BlaEigen.c:37
void fasp_blas_dcsr_mxv(const dCSRmat *A, const REAL *x, REAL *y)
Matrix-vector multiplication y = A*x.
Definition: BlaSpmvCSR.c:242
REAL fasp_blas_dcsr_vmv(const dCSRmat *A, const REAL *x, const REAL *y)
vector-Matrix-vector multiplication alpha = y'*A*x
Definition: BlaSpmvCSR.c:839
REAL fasp_blas_dvec_norm2(const dvector *x)
L2 norm of dvector x.
Definition: BlaVector.c:170
Main header file for the FASP project.
#define REAL
Definition: fasp.h:75
#define ABS(a)
Definition: fasp.h:84
#define INT
Definition: fasp.h:72
Sparse matrix of REAL type in CSR format.
Definition: fasp.h:151
INT row
row number of matrix A, m
Definition: fasp.h:154
Vector with n entries of REAL type.
Definition: fasp.h:354
REAL * val
actual vector entries
Definition: fasp.h:360