-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathNLC_2D_TFIM.cpp
136 lines (112 loc) · 4.71 KB
/
NLC_2D_TFIM.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*******************************************************************
Linked Cluster Expansion program for the 1D TFIM model
Roger Melko, Ann Kallin, Katie Hyatt June 2012
baesd on a Lanczos code from November 2007
********************************************************************/
#include <utility>
#include <fstream>
#include <vector>
#include <math.h>
using namespace std;
#include <iostream>
#include <limits.h>
#include <stdio.h>
#include <time.h>
#include <iomanip>
#include <string>
#include "CPU/Lanczos_07.h"
#include "CPU/GenHam.h"
#include "CPU/simparam.h"
#include "CPU/magnetization.h"
#include "../Graphs/graphs.h"
int main(int argc, char** argv){
int CurrentArg = 1;
string InputFile;
string OutputFile = "output_2d.dat";
bool MagFlag = false;
while (CurrentArg < argc)
{
if (argv[ CurrentArg ] == string("-i") || argv[ CurrentArg ] == string("--input"))
{
InputFile = string(argv[ CurrentArg + 1 ]);
}
if (argv[ CurrentArg ] == string("-o") || argv[ CurrentArg ] == string("--output"))
{
OutputFile = string(argv[ CurrentArg + 1 ]);
}
if (argv[ CurrentArg ] == string("-m") || argv[ CurrentArg ] == string("--mag"))
{
MagFlag = true;
}
CurrentArg++;
}
double energy;
double chi;
PARAMS prm; //Read parameters from param.dat : see simparam.h
double J;
double h;
vector <long double> eVec;
J=prm.JJ_;
h=prm.hh_;
vector< Graph > fileGraphs; //graph objects
vector<double> EnergyWeightHigh;
vector<double> MagnetWeightHigh;
ReadGraphsFromFile(fileGraphs, InputFile);
ofstream fout(OutputFile.c_str());
fout.precision(10);
cout.precision(10);
J=1.;
for(double hh = 1; hh < 5; hh += 2.){
h = hh;
EnergyWeightHigh.push_back(-h); //Weight for site zero
MagnetWeightHigh.push_back(1.);
double EnergyRunningSumHigh = EnergyWeightHigh[0];
double MagnetRunningSumHigh = MagnetWeightHigh[0];
for (unsigned int i=1; i<fileGraphs.size(); i++){ //skip the zeroth graph
//---High-Field---
GENHAM HV(fileGraphs.at(i).Order, J, h, fileGraphs.at(i).AdjacencyList, fileGraphs.at(i).LowField);
LANCZOS lancz(HV.Vdim); //dimension of reduced Hilbert space (Sz sector)
HV.SparseHamJQ(); //generates sparse matrix Hamiltonian for Lanczos
if(MagFlag)
{
energy = lancz.Diag(HV, 1, 2, eVec); // Hamiltonian, # of eigenvalues to converge, 1 for -values only, 2 for vals AND vectors
chi = Magnetization(eVec, fileGraphs.at(i).Order);
eVec.clear();
MagnetWeightHigh.push_back(chi);
}
else
{
energy = lancz.Diag(HV, 1, 1, eVec); // Hamiltonian, # of eigenvalues to converge, 1 for -values only, 2 for vals AND vectors
}
cout<<"Energy: "<<energy<<endl;
EnergyWeightHigh.push_back(energy);
for (unsigned int j = 0; j < fileGraphs[ i ].SubgraphList.size(); j++)
{
EnergyWeightHigh.back() -= fileGraphs[ i ].SubgraphList[ j ].second * EnergyWeightHigh[ fileGraphs[ i ].SubgraphList[ j ].first ];
if( MagFlag ) MagnetWeightHigh.back() -= fileGraphs[ i ].SubgraphList[ j ].second * MagnetWeightHigh[ fileGraphs[ i ].SubgraphList[ j ].first ];
}
// cout<<"WeightHigh["<<i<<"] = "<<WeightHigh.back()<<endl;
EnergyRunningSumHigh += fileGraphs[ i ].LatticeConstant * EnergyWeightHigh.back();
//cout<<"This cluster's order: "<<fileGraphs[i].Order<<" Lattice Constant: "<<fileGraphs[i].LatticeConstant<<endl;
//cout<<"Magnetization for this cluster: "<<chi<<endl;
//cout<<"Energy for this cluster: "<<energy<<endl;
//cout<<"Magnetization Weight High: "<<MagnetWeightHigh.back()<<endl;
if (MagFlag && fabs(fileGraphs[ i ].LatticeConstant * MagnetWeightHigh.back()) > 1.0)
{
fout<<"In the "<<fileGraphs.at(i).Identifier<<"th graph, magnetization weight of "<<fileGraphs[ i ].LatticeConstant * MagnetWeightHigh.back()<<endl;
}
if (MagFlag) MagnetRunningSumHigh += fileGraphs[ i ].LatticeConstant * MagnetWeightHigh.back();
cout<<"h = "<<hh<<" J = "<<J<<" Energy Running Sum: "<<EnergyRunningSumHigh<<endl;
if (MagFlag) cout<<" Magnet Running Sum: "<<MagnetRunningSumHigh<<endl;
}
fout<<"h= "<<h<<" J= "<<J;
fout <<" Energy= "<< EnergyRunningSumHigh<<endl;
if(MagFlag) fout<<" Magnet= "<<MagnetRunningSumHigh<<endl;
EnergyWeightHigh.clear();
MagnetWeightHigh.clear();
EnergyRunningSumHigh=0;
MagnetRunningSumHigh=0;
}
fout.close();
return 0;
}