9 #define max(a, b) ((a) > (b) ? (a) : (b))
10 #define min(a, b) ((a) < (b) ? (a) : (b))
11 int findarg(
const char *argname,
ARG_TYPE type,
void *val,
int argc,
char **argv);
13 int exeiglap3(
int nx,
int ny,
int nz,
double a,
double b,
int *m,
double **vo);
27 int main(
int argc,
char *argv[]) {
42 int n, nx, ny, nz, i, j, npts, nslices, nvec, Mdeg, nev,
43 mlan, ev_int, sl, flg, ierr;
45 double a, b, lmax, lmin, ecount, tol, *sli, *mu;
51 if (stat(
"OUT", &st) == -1) {
56 if (!(fstats = fopen(
"OUT/LapPLanN_MatFree.out",
"w"))) {
57 printf(
" failed in opening output file in OUT/\n");
70 flg =
findarg(
"help",
NA, NULL, argc, argv);
72 printf(
"Usage: ./testL.ex -nx [int] -ny [int] -nz [int] -a [double] -b [double] -nslices [int]\n");
81 fprintf(fstats,
"used nx = %3d ny = %3d nz = %3d",nx,ny,nz);
82 fprintf(fstats,
" [a = %4.2f b= %4.2f], nslices=%2d \n",a,b,nslices);
85 double stencil[7] = {0.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0};
86 stencil[0] = nz <= 1 ? 4.0 : 6.0;
89 lapmv.
nx = nx; lapmv.
ny = ny; lapmv.
nz = nz; lapmv.
stencil = stencil;
92 lmax = nz == 1 ? 8.0 : 12.0;
100 fprintf(fstats,
"- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
101 fprintf(fstats,
"Laplacian: %d x %d x %d, n = %d\n", nx, ny, nz, n);
102 fprintf(fstats,
"Interval: [%20.15f, %20.15f] -- %d slices \n", a, b, nslices);
104 fprintf(fstats,
"Step 0: Eigenvalue bound s for A: [%.15e, %.15e]\n", lmin, lmax);
115 mu = malloc((Mdeg+1)*
sizeof(
double));
117 ierr =
kpmdos(Mdeg, 1, nvec, xintv, mu, &ecount);
120 printf(
"kpmdos error %d\n", ierr);
123 fprintf(fstats,
" Time to build DOS (kpmdos) was : %10.2f \n",t);
124 fprintf(fstats,
" estimated eig count in interval: %.15e \n",ecount);
127 sli = malloc((nslices+1)*
sizeof(
double));
129 fprintf(fstats,
"DOS parameters: Mdeg = %d, nvec = %d, npnts = %d\n",Mdeg, nvec, npts);
130 ierr =
spslicer(sli, mu, Mdeg, xintv, nslices, npts);
132 printf(
"spslicer error %d\n", ierr);
135 printf(
"==================== SLICES FOUND ====================\n");
136 for (j=0; j<nslices;j++) {
137 printf(
" %2d: [% .15e , % .15e]\n", j+1, sli[j],sli[j+1]);
140 ev_int = (int) (1 + ecount / ((
double) nslices));
142 vinit = (
double *) malloc(n*
sizeof(
double));
147 for (sl =0; sl<nslices; sl++){
148 printf(
"======================================================\n");
150 double *lam, *Y, *res;
157 printf(
" subinterval: [%.4e , %.4e]\n", a, b);
161 mlan =
max(4*nev, 300);
164 xintv[0] = a; xintv[1] = b;
165 xintv[2] = lmin; xintv[3] = lmax;
181 fprintf(fstats,
" polynomial [type = %d], deg %d, bar %e gam %e\n",
184 ierr =
ChebLanNr(xintv, mlan, tol, vinit, &pol, &nev2, &lam, &Y, &res, fstats);
186 printf(
"ChebLanNr error %d\n", ierr);
193 ind = (
int *) malloc(nev2*
sizeof(
int));
196 exeiglap3(nx, ny, nz, a, b, &nev_ex, &lam_ex);
197 printf(
" number of eigenvalues: %d, found: %d\n", nev_ex, nev2);
200 fprintf(fstats,
" Eigenvalues in [a, b]\n");
201 fprintf(fstats,
" Computed [%d] ||Res|| Exact [%d]", nev2, nev_ex);
202 if (nev2 == nev_ex) {
203 fprintf(fstats,
" Err");
205 fprintf(fstats,
"\n");
206 for (i=0; i<
max(nev2, nev_ex); i++) {
208 fprintf(fstats,
"% .15e %.1e", lam[i], res[ind[i]]);
210 fprintf(fstats,
" ");
213 fprintf(fstats,
" % .15e", lam_ex[i]);
215 if (nev2 == nev_ex) {
216 fprintf(fstats,
" % .1e", lam[i]-lam_ex[i]);
218 fprintf(fstats,
"\n");
220 fprintf(fstats,
" -- More not shown --\n");
251 double *stencil = lapmv->
stencil;
254 for (k=0; k<nz; k++) {
255 for (j=0; j<ny; j++) {
256 for (i=0; i<nx; i++) {
257 p = k*nx*ny + j*nx + i;
258 y[p] = stencil[0] * x[p];
260 if (i>0) { y[p] += stencil[1] * x[p-1]; }
261 if (i<nx-1) { y[p] += stencil[2] * x[p+1]; }
263 if (j>0) { y[p] += stencil[3] * x[p-nx]; }
264 if (j<ny-1) { y[p] += stencil[4] * x[p+nx]; }
266 if (k>0) { y[p] += stencil[5] * x[p-nx*ny]; }
267 if (k<nz-1) { y[p] += stencil[6] * x[p+nx*ny]; }
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 exeiglap3(int nx, int ny, int nz, double a, double b, int *m, double **vo)
Exact eigenvalues of Laplacean in interval [a b].
void free_pol(polparams *pol)
void rand_double(int n, double *v)
int find_pol(double *intv, polparams *pol)
Sets the values in pol.
void sort_double(int n, double *v, int *ind)
int lapgen(int nx, int ny, int nz, cooMat *Acoo)
Laplacean Matrix generator.
int EVSLStart()
Initialize evslData.
void set_pol_def(polparams *pol)
set default values for polparams struct.
This file contains function prototypes and constant definitions for EVSL.
int EVSLFinish()
Finish EVSL.
int ChebLanNr(double *intv, int maxit, double tol, double *vinit, polparams *pol, int *nevOut, double **lamo, double **Wo, double **reso, FILE *fstats)
int findarg(const char *argname, ARG_TYPE type, void *val, int argc, char **argv)
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...
int main(int argc, char *argv[])
void Lap2D3DMatvec(double *x, double *y, void *data)
parameters for polynomial filter
sparse matrix format: the coordinate (COO) format, 0-based
int SetAMatvec(int n, MVFunc func, void *data)
Set the user-input matvec routine and the associated data for A. Save them in evsldata.
double evsl_timer()
evsl timer for mac