43 int LanDosG(
const int nvec,
const int msteps,
int npts,
double *xdos,
double *ydos,
44 double *neig,
const double *
const intv) {
47 int maxit = msteps, m;
63 maxit =
min(n, maxit);
64 size_t maxit_l = maxit;
66 Calloc(gamma2, maxit,
double);
71 double *V, *dT, *eT, *Z;
72 Calloc(V, n_l * (maxit + 1),
double);
75 Calloc(Z, n_l * (maxit + 1),
double);
83 double *EvalT, *EvecT;
84 Malloc(EvalT, maxit,
double);
85 Malloc(EvecT, maxit_l * maxit_l,
double);
86 const double lm = intv[2];
87 const double lM = intv[3];
88 const double aa =
max(intv[0], intv[2]);
89 const double bb =
min(intv[1], intv[3]);
90 const double kappa = 1.25;
91 const int M =
min(msteps, 30);
92 const double H = (lM - lm) / (M - 1);
93 const double sigma = H / sqrt(8 * log(kappa));
94 const double sigma2 = 2 * sigma * sigma;
96 const double tol = 1e-08;
97 double width = sigma * sqrt(-2.0 * log(tol));
101 const size_t wk_size = ifGenEv ? 6 * n_l : 4 * n_l;
102 Malloc(wk, wk_size,
double);
103 for (m = 0; m < nvec; m++) {
115 t = 1.0 / sqrt(
DDOT(&n, V, &one, Z, &one));
116 DSCAL(&n, &t, Z, &one);
119 t = 1.0 /
DNRM2(&n, vinit, &one);
120 DCOPY(&n, vinit, &one, V, &one);
123 DSCAL(&n, &t, V, &one);
129 double *zold, *z, *znew;
132 double alpha, nalpha, beta = 0.0, nbeta;
134 for (k = 0; k < maxit; k++) {
136 zold = k > 0 ? Z + (k - 1) * n_l : NULL;
149 DAXPY(&n, &nbeta, zold, &one, znew, &one);
152 alpha =
DDOT(&n, v, &one, znew, &one);
158 DAXPY(&n, &nalpha, z, &one, znew, &one);
166 beta = sqrt(
DDOT(&n, vnew, &one, znew, &one));
175 if (beta * nwn <
orthTol * wn) {
181 matvec_B(vnew, znew);
182 beta = sqrt(
DDOT(&n, vnew, &one, znew, &one));
185 DSCAL(&n, &t, vnew, &one);
187 DSCAL(&n, &t, znew, &one);
195 DSCAL(&n, &t, vnew, &one);
201 DSCAL(&n, &t, vnew, &one);
204 DSCAL(&n, &t, znew, &one);
211 for (i = 0; i < maxit; i++) {
215 gamma2[i] = EvecT[i * maxit_l] * EvecT[i * maxit_l];
219 for (i = 0; i < msteps; i++) {
221 const double t = EvalT[i];
224 for (j = 0; j < npts; j++) {
225 if (fabs(xdos[j] - t) < width) ind[numPlaced++] = j;
227 for (j = 0; j < numPlaced; j++) {
228 y[ind[j]] += gamma2[i] *
229 exp(-((xdos[ind[j]] - t) * (xdos[ind[j]] - t)) / sigma2);
233 double scaling = 1.0 / (nvec * sqrt(sigma2 *
PI));
235 DSCAL(&npts, &scaling, y, &one);
236 DCOPY(&npts, y, &one, ydos, &one);
238 *neig = y[npts - 1] * n;
double DDOT(int *n, double *x, int *incx, double *y, int *incy)
void rand_double(int n, double *v)
void CGS_DGKS(int n, int k, int i_max, double *Q, double *v, double *nrmv, double *w)
Classical GS reortho with Daniel, Gragg, Kaufman, Stewart test.
void DSCAL(int *n, double *a, double *x, int *incx)
#define Calloc(base, nmem, type)
int SymmTridEig(double *eigVal, double *eigVec, int n, const double *diag, const double *sdiag)
compute all eigenvalues and eigenvectors of a symmetric tridiagonal matrix
This file contains function prototypes and constant definitions internally used in EVSL...
#define Malloc(base, nmem, type)
void randn_double(int n, double *v)
int LanDosG(const int nvec, const int msteps, int npts, double *xdos, double *ydos, double *neig, const double *const intv)
void CGS_DGKS2(int n, int k, int i_max, double *Z, double *Q, double *v, double *w)
Classical GS reortho. No test. just do i_max times used in generalized ev problems.
void DAXPY(int *n, double *alpha, double *x, int *incx, double *y, int *incy)
This file contains function prototypes and constant definitions for EVSL.
double DNRM2(int *n, double *x, int *incx)
Defs for blaslapack routines.
evslData evsldata
global variable of EVSL
void linspace(double a, double b, int num, double *arr)
void simpson(double *xi, double *yi, int npts)
void DCOPY(int *n, double *dx, int *incx, double *dy, int *incy)