28 #define HDF5_STATUS_CHECK(status) { \
30 std::cerr << __FILE__ << ":" << __LINE__ << \
31 ": Problem with writing to file. Status code=" \
32 << status << std::endl; \
52 std::cerr <<
"We cannot do more then 30 sites" << std::endl;
55 std::cerr <<
"Too many electrons for this lattice" << std::endl;
108 return __builtin_popcount(bits);
120 std::string output =
"";
121 output.reserve(bitcount);
123 for(
int i=bitcount-1;i>=0;i--)
183 sign =
CountBits(( ((1<<j) - 1) ^ ((1<<(i+1)) - 1) ) & a);
284 std::vector<double> eigenvalues(
dim);
299 for(
int i=0;i<
dim;i++)
302 int a = (i - b)/NumDown;
318 std::vector<double> a(m,0);
319 std::vector<double> b(m,0);
321 double *qa =
new double [
dim];
322 double *qb =
new double [
dim];
333 qb[i] = rand()*1.0/RAND_MAX;
338 double norm = 1.0/sqrt(
ddot_(&dim,qb,&incx,qb,&incx));
340 dscal_(&dim,&norm,qb,&incx);
350 std::vector<double> acopy(a);
351 std::vector<double> bcopy(b);
355 while(fabs(E-acopy[0]) > 1e-4)
362 dscal_(&dim,&alpha,f1,&incx);
366 a[i-1] =
ddot_(&dim,f1,&incx,f2,&incx);
369 daxpy_(&dim,&alpha,f2,&incx,f1,&incx);
371 b[i] = sqrt(
ddot_(&dim,f1,&incx,f1,&incx));
373 if( fabs(b[i]) < 1e-10 )
378 dscal_(&dim,&alpha,f1,&incx);
391 dstev_(&jobz,&m,acopy.data(),&bcopy.data()[1],&alpha,&m,&alpha,&info);
394 std::cerr <<
"Error in Lanczos" << std::endl;
412 for(
int i=0;i<
dim;i++)
415 for(
int j=0;j<
dim;j++)
416 std::cout << i <<
"\t" << j <<
"\t\t" <<
ham[i+j*dim] << std::endl;
419 for(
int j=0;j<
dim;j++)
420 std::cout <<
ham[i+j*dim] <<
"\t";
421 std::cout << std::endl;
431 for(
unsigned int a=0;a<
baseUp.size();a++)
432 for(
unsigned int b=0;b<
baseDown.size();b++)
449 char which[] = {
'S',
'A'};
454 double *resid =
new double[n];
466 double *v =
new double[ldv*ncv];
468 int *iparam =
new int[11];
478 int *ipntr =
new int[11];
483 double *workd =
new double[3*n];
485 int lworkl = ncv*(ncv+8);
486 double *workl =
new double[lworkl];
502 select =
new int[ncv];
505 double *d =
new double[nev];
510 z =
new double[n*nev];
516 dsaupd_(&ido, &bmat, &n, &which[0], &nev, &tol, resid, &ncv, v, &ldv, iparam, ipntr, workd, workl, &lworkl, &info);
521 mvprod(workd+ipntr[0]-1, workd+ipntr[1]-1,0);
523 dsaupd_(&ido, &bmat, &n, &which[0], &nev, &tol, resid, &ncv, v, &ldv, iparam, ipntr, workd, workl, &lworkl, &info);
527 std::cerr <<
"Error with dsaupd, info = " << info << std::endl;
528 else if ( info == 1 )
529 std::cerr <<
"Maximum number of Lanczos iterations reached." << std::endl;
530 else if ( info == 3 )
531 std::cerr <<
"No shifts could be applied during implicit Arnoldi update, try increasing NCV." << std::endl;
533 dseupd_(&rvec, &howmny, select, d, z, &ldv, &sigma, &bmat, &n, which, &nev, &tol, resid, &ncv, v, &ldv, iparam, ipntr, workd, workl, &lworkl, &info);
536 std::cerr <<
"Error with dseupd, info = " << info << std::endl;
543 std::stringstream name;
544 name <<
"results-" <<
L <<
"-" <<
Nu <<
"-" <<
Nd <<
"-" <<
U <<
".h5";
600 result += dim * dim *
sizeof(double);
603 result += dim *
sizeof(double);
606 result += (2*dim+1) *
sizeof(
double);
632 result += 2 * dim *
sizeof(double);
659 result += 1 * dim *
sizeof(double);
662 result += 16 * dim *
sizeof(double);
665 result += 3 * dim *
sizeof(double);
668 result += 16 * (16+8) *
sizeof(
double);
683 assert(mat &&
"mat must be allocated");
684 assert(eigs &&
"eigs must be allocated");
688 if(calc_eigenvectors)
697 if(calc_eigenvectors)
699 lwork = 6*dim+1+2*dim*
dim;
707 double *work =
new double[lwork];
709 int *iwork =
new int[liwork];
713 dsyevd_(&jobz, &uplo, &dim, mat, &dim, eigs, work, &lwork, iwork, &liwork, &info);
716 std::cerr <<
"Calculating eigenvalues failed..." << std::endl;
743 hid_t file_id, dataset_id, dataspace_id, attribute_id;
746 file_id = H5Fcreate(filename.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
749 hsize_t dimarr =
dim;
751 dataspace_id = H5Screate_simple(1, &dimarr, NULL);
753 dataset_id = H5Dcreate(file_id,
"ham", H5T_IEEE_F64LE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
755 status = H5Dwrite(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, data );
758 status = H5Sclose(dataspace_id);
761 dataspace_id = H5Screate(H5S_SCALAR);
763 attribute_id = H5Acreate (dataset_id,
"L", H5T_STD_I32LE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT);
764 status = H5Awrite (attribute_id, H5T_NATIVE_INT, &
L );
766 status = H5Aclose(attribute_id);
769 attribute_id = H5Acreate (dataset_id,
"Nu", H5T_STD_I32LE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT);
770 status = H5Awrite (attribute_id, H5T_NATIVE_INT, &
Nu );
772 status = H5Aclose(attribute_id);
775 attribute_id = H5Acreate (dataset_id,
"Nd", H5T_STD_I32LE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT);
776 status = H5Awrite (attribute_id, H5T_NATIVE_INT, &
Nd );
778 status = H5Aclose(attribute_id);
781 attribute_id = H5Acreate (dataset_id,
"J", H5T_IEEE_F64LE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT);
782 status = H5Awrite (attribute_id, H5T_NATIVE_DOUBLE, &
J );
784 status = H5Aclose(attribute_id);
787 attribute_id = H5Acreate (dataset_id,
"U", H5T_IEEE_F64LE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT);
788 status = H5Awrite (attribute_id, H5T_NATIVE_DOUBLE, &
U );
790 status = H5Aclose(attribute_id);
793 attribute_id = H5Acreate (dataset_id,
"dim", H5T_STD_I32LE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT);
794 status = H5Awrite (attribute_id, H5T_NATIVE_INT, &dim );
796 status = H5Aclose(attribute_id);
799 status = H5Sclose(dataspace_id);
802 status = H5Dclose(dataset_id);
805 status = H5Fclose(file_id);