32 int kpmdos(
int Mdeg, 
int damping, 
int nvec, 
double *intv,
 
   33     double *mu, 
double *ecnt) {
 
   37   double *vkp1, *v, *vkm1, *vk, *jac;
 
   47   Malloc(jac, Mdeg+1, 
double);
 
   48   double *tmp,  ctr, wid; 
 
   49   double scal, t, tcnt, beta1, beta2, aa, bb;
 
   50   int k, k1, i, m, mdegp1, one=1;
 
   52   if (check_intv(intv, stdout) < 0) {
 
   56   aa = 
max(intv[0], intv[2]);  bb = 
min(intv[1], intv[3]);
 
   57   if (intv[0] < intv[2] || intv[1] > intv[3]) {
 
   58     fprintf(stdout, 
" warning [%s (%d)]: interval (%e, %e) is adjusted to (%e, %e)\n",
 
   59             __FILE__, __LINE__, intv[0], intv[1], aa, bb);
 
   62   ctr  = (intv[3]+intv[2])/2.0;
 
   63   wid  = (intv[3]-intv[2])/2.0;
 
   64   t = 
max(-1.0+DBL_EPSILON, (aa-ctr)/wid);
 
   66   t = 
min(1.0-DBL_EPSILON, (bb-ctr)/wid);
 
   69   dampcf(Mdeg, damping, jac);
 
   72   memset(mu,0,(Mdeg+1)*
sizeof(
double));
 
   78   for (m=0; m<nvec; m++) {
 
   82       t = 1.0 / 
DNRM2(&n, v, &one);
 
   83       DSCAL(&n, &t, v, &one);  
 
   88       t = 
DDOT(&n, v, &one, w, &one);
 
   89       memcpy(vk, w, n*
sizeof(
double));
 
   93       t = 1.0 / 
DNRM2(&n, v, &one);
 
   94       DSCAL(&n, &t, v, &one);
 
   95       memcpy(vk, v, n*
sizeof(
double));
 
   98     memset(vkm1, 0, n*
sizeof(
double));
 
  101     tcnt -= jac[0]*(beta2-beta1);  
 
  103     for (k=0; k<Mdeg; k++){
 
  112       scal = k==0 ? 1.0 : 2.0;
 
  114       for (i=0; i<n; i++) {
 
  115         vkp1[i] = scal*(vkp1[i]-ctr*vk[i]) - vkm1[i];
 
  124       t = 2*jac[k1] * 
DDOT(&n, vk, &one, v, &one);
 
  127       tcnt -= t*(sin(k1*beta2)-sin(k1*beta1))/k1;  
 
  131   t = 1.0 /(((double)nvec)*
PI) ;
 
  133   DSCAL(&mdegp1, &t, mu, &one) ;
 
  134   tcnt *= t*((double) n);
 
  154 void intChx(
const int Mdeg, 
double *mu, 
const int npts, 
double *xi, 
double *yi) {
 
  158     fprintf(stderr, 
"Must have more than 0 points");
 
  161   double val0, theta0, *thetas;
 
  162   Malloc(thetas, npts, 
double);
 
  167   for (j=0; j<npts; j++)
 
  168     thetas[j] = acos(xi[j]);
 
  170   for (j=0; j<npts; j++) 
 
  171     yi[j] = mu[0]*(theta0 - thetas[j]);
 
  173   for (k=1; k<ndp1; k++){
 
  174     val0 = sin(k*theta0)/k;
 
  176     for (j=0; j<npts; j++)
 
  177       yi[j] += mu[k]*(val0 - sin(k*thetas[j])/k);
 
  204 int spslicer(
double *sli, 
double *mu, 
int Mdeg, 
double *intv, 
int n_int, 
int npts) {
 
  206   double  ctr, wid, aL, bL, target, aa, bb;
 
  208   if (check_intv(intv, stdout) < 0) {
 
  213   aa = 
max(intv[0], intv[2]);  bb = 
min(intv[1], intv[3]);
 
  214   if (intv[0] < intv[2] || intv[1] > intv[3]) {
 
  215     fprintf(stdout, 
" warning [%s (%d)]:  interval (%e, %e) is adjusted to (%e, %e)\n",
 
  216         __FILE__, __LINE__, intv[0], intv[1], aa, bb);
 
  220   memset(sli,0,(n_int+1)*
sizeof(
double));
 
  229   ctr = (intv[3] + intv[2])/2;
 
  230   wid = (intv[3] - intv[2])/2;
 
  235   npts = 
max(npts,2*n_int+1);
 
  243   intChx(Mdeg, mu, npts, xi, yi) ; 
 
  245   target = yi[npts-1] / (double)n_int;
 
  251   while (++ls < n_int) {
 
  252     while (ii < npts && yi[ii] < target) {
 
  259     if ( (target-yi[ii-1]) < (yi[ii]-target)) {
 
  262     sli[ls] = ctr + wid*xi[ii];
 
  264     target = yi[ii] + (yi[npts-1] - yi[ii])/(n_int-ls);
 
  269   sli[n_int] = intv[1];
 
  275   for (ii=1; ii<=n_int; ii++) {
 
  276     if (sli[ii] < sli[ii-1]) {
 
  284     for (ii=0; ii<=n_int; ii++) {
 
  285       printf(
"%.15f\n", sli[ii]);
 
int kpmdos(int Mdeg, int damping, int nvec, double *intv, double *mu, double *ecnt)
This function computes the coefficients of the density of states in the chebyshev basis...
int time_seeder()
Uses the timer to generate a seed to be used for srand. 
double DDOT(int *n, double *x, int *incx, double *y, int *incy)
void rand_double(int n, double *v)
void save_vec(int n, const double *x, const char fn[])
void intChx(const int Mdeg, double *mu, const int npts, double *xi, double *yi)
Computes the integrals  where p(t) is the approximate DOS as given in the KPM method in the expanded ...
void DSCAL(int *n, double *a, double *x, int *incx)
This file contains function prototypes and constant definitions internally used in EVSL...
#define Malloc(base, nmem, type)
int spslicer(double *sli, double *mu, int Mdeg, double *intv, int n_int, int npts)
given the dos function defined by mu find a partitioning of sub-interval [a,b] of the spectrum so eac...
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)
int dampcf(int m, int damping, double *jac)
Computes damping coefficient for cheb. expansions.