Skip to content

Commit

Permalink
Added an input file
Browse files Browse the repository at this point in the history
  • Loading branch information
wsttiger committed Sep 30, 2015
1 parent 3383a10 commit 54ddaa4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
29 changes: 15 additions & 14 deletions heisen.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,26 +328,24 @@ class HeisenCalculation {
// astream.close();
// }

HeisenCalculation(int sites) {
create_ring(sites);
HeisenCalculation(int sites, int sector) {
create_ring(sites, sector);
}

void create_ring(int sites) {
void create_ring(int sites, int sector) {
double J = 1.0;
for (int i = 0; i < sites-1; i++) {
lattice.push_back(Bond(i,i+1,J));
}
lattice.push_back(Bond(sites-1,0,J));
sectors.push_back(Sector(lattice,sites,1));

// double J = 1.0;
// for (int i = 0; i < sites-1; i++) {
// lattice.push_back(Bond(i,i+1,J));
// }
// lattice.push_back(Bond(sites-1,0,J));
// for (int i = 0; i < sites; i++) {
// sectors.push_back(Sector(lattice,sites,i));
// }
if (sector <= 0) {
for (int i = 0; i < sites; i++) {
sectors.push_back(Sector(lattice,sites,i));
}
}
else {
sectors.push_back(Sector(lattice,sites,sector));
}
}

vector<double> eigenvalues() {
Expand All @@ -359,8 +357,11 @@ class HeisenCalculation {
vector<double> mat = s.make_matrix();
vector<double> es(nst,0.0);
vector<double> ev(nst*nst,0.0);
const auto tstart = std::chrono::system_clock::now();
diag_matrix(mat,nst,es,ev);
print_matrix(mat,nst,nst);
const auto tstop = std::chrono::system_clock::now();
const std::chrono::duration<double> time_elapsed = tstop - tstart;
std::cout << "Diagonalization took " << time_elapsed.count() << " s" << std::endl;
std::copy(es.begin(),es.end(),std::back_inserter(e));
}
std::sort(e.begin(),e.end(),[](const double& a, const double& b) {return a < b;});
Expand Down
3 changes: 2 additions & 1 deletion read.in
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
4
14
6
15 changes: 14 additions & 1 deletion test_heisen.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
#include "heisen.h"

int main(int argc, char** argv) {
HeisenCalculation calc(4);
ifstream f("read.in");
int nsites = 4;
int sector = -1;
if (f.is_open()) {
f >> nsites;
f >> sector;
printf("read.in --> nsites = %d sector = %d\n", nsites, sector);
f.close();
}
HeisenCalculation calc(nsites,sector);
// const auto tstart = std::chrono::system_clock::now();
vector<double> e = calc.eigenvalues();
// const auto tstop = std::chrono::system_clock::now();
// const std::chrono::duration<double> time_elapsed = tstop - tstart;
print_vector(e);
// std::cout << "Calculation took " << time_elapsed.count() << " s" << std::endl;
return 0;
}

0 comments on commit 54ddaa4

Please sign in to comment.