StatMech
Loading...
Searching...
No Matches
RestrictionToMBodyOperators_MeanOp.cpp File Reference

Classes

class  MagmaController
 

Typedefs

using SubHilbertSpace = TransSector< double >
 

Functions

int main (int argc, char **argv)
 

Typedef Documentation

◆ SubHilbertSpace

using SubHilbertSpace = TransSector<double>

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)
73 {
74 if(argc != 13) {
75 std::cerr << "Usage: 1.(This) 2.(dimLoc) 3.(LMax) 4.(LMin) 4.(mMax) 5.(mMin) 6.(momentum) "
76 "7.(shellWidth) "
77 "8.(repMin) 9.(repMax) 10.(opRepMin) 11.(opRepMax) 12.(OutDir)\n"
78 << "argc = " << argc << std::endl;
79 std::exit(EXIT_FAILURE);
80 }
81 int const dimLoc = std::atoi(argv[1]);
82 int const LMax = std::atoi(argv[2]);
83 int const LMin = std::atoi(argv[3]);
84 int const mMax = std::atoi(argv[4]);
85 int const mMin = std::atoi(argv[5]);
86 int const k = std::atoi(argv[6]);
87 double const shellWidth = std::atof(argv[7]);
88 int const repMin = std::atoi(argv[8]);
89 int const repMax = std::atoi(argv[9]);
90 int const opRepMin = std::atoi(argv[10]);
91 int const opRepMax = std::atoi(argv[11]);
92 std::string baseDirName(argv[12]);
93 baseDirName += "/TypicalityOfETH/";
94 baseDirName += QUOTE(ENSEMBLE);
95 std::ofstream OutFs;
96
97#ifdef MAGMA
99
100 // cuCHECK(cudaDeviceSetLimit(cudaLimitMallocHeapSize, size_t(4) * size_t(1024 * 1024 * 1024)));
101 // Setting the heap size too large causes a "double free or corruption" error on some of the destructObject_kernel calls.
102 std::size_t heapSize, stackSize;
103 cuCHECK(cudaDeviceGetLimit(&stackSize, cudaLimitStackSize));
104 cuCHECK(cudaDeviceGetLimit(&heapSize, cudaLimitMallocHeapSize));
105 std::cout << "Max stack size = " << stackSize << " bytes \n"
106 << "Max heap size = " << heapSize << " bytes \n"
107 << std::endl;
108#endif
109
110 double EnergyRange, groundEnergy, diff;
111 HilbertSpace<int> const H_loc(dimLoc);
112 RandomMatrixEnsemble ensemble(H_loc); //GUEgenerator<> GUE(0, 1);
113 // Requirements for class RandomMatrixEnsemble
114 // -method discardSamples(int)
115 // -method getNewSample(void)
116 // -method constructHamiltonian(int)
117
118 int dimTot;
119 {
120 SubHilbertSpace const transSector(k, LMax, dimLoc);
121 dimTot = transSector.dim();
122 }
123 std::cout << "\t dimTot = " << dimTot << "\n\n\n" << std::endl;
124
125 Eigen::MatrixXd ETHmeasure;
126 Eigen::VectorXd eigEnergy, theorySum, colVec;
127
129#ifdef GPU
131 Eigen::Matrix<Complex_t<Real_t>, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>> >
132 eigenSolver(dimTot);
133#else
135#endif
136
137 debug_print("baseDirName = " << baseDirName);
138
139 double start, t_int, end, temp_t;
140 double T_diag = 0, T_post = 0, T_pre = 0, T_IO = 0;
141
142 ensemble.discardSamples(repMin); //GUE.discard(repMin - 1); // discardSamples(repMin-1);
143 debug_print(repMin << " samples are discarded.");
144
145 start = getETtime();
146 end = start;
147 for(auto repetition = repMin; repetition <= repMax; ++repetition) {
148 temp_t = getETtime();
149 std::string outDirName(baseDirName);
150 {
151 std::stringstream buff;
152 buff << "/RawData/Hamiltonian_No" << repetition;
153 outDirName += buff.str();
154 outDirName = std::regex_replace(outDirName, std::regex("//"), "/");
155 if(!std::filesystem::exists(outDirName)
156 && !std::filesystem::create_directories(outDirName)) {
157 std::cerr << "Error: Failed to create directories " << outDirName << std::endl;
158 std::exit(EXIT_FAILURE);
159 };
160 }
161 debug_print("repetition = " << repetition);
162
163 ensemble.getNewSample();
164 T_IO += getETtime() - temp_t;
165
166 for(int L = LMax; L >= LMin; --L) {
167 temp_t = getETtime();
168 // { // Construct a sector of a many-body Hilbert space and a Hamiltonian within that sector
169 ManyBodySpinSpace const H_tot(L, H_loc);
170 SubHilbertSpace const transSector(k, H_tot);
171
172 eigenSolver.inMatrix().resize(transSector.dim(), transSector.dim());
173 eigEnergy.resize(transSector.dim());
174 ETHmeasure = Eigen::MatrixXd::Zero(transSector.dim(), L + 1).eval();
175 diff = ETHmeasure.norm();
176 if(diff > 1.0e-4) {
177 std::cerr << "Error : failed to initialize ETHmeasure: diff = " << diff
178 << " is too large." << std::endl;
179 std::exit(EXIT_FAILURE);
180 }
181 debug_print("eigenSolver.inMatrix():\n" << eigenSolver.inMatrix());
182 ensemble.constructHamiltonian(eigenSolver.inMatrix(), transSector);
183 // }
184 T_pre += getETtime() - temp_t;
185
186 // Diagonalize the Hamiltonian to obtain eigenvalues and eigenvectors
187 temp_t = getETtime();
188 { eigenSolver.compute(); }
189 T_diag += getETtime() - temp_t;
190 // debug_print("eigenSolver.eigenvalues(): After diagonalization\n"
191 // << eigenSolver.eigenvalues());
192 // debug_print("eigenSolver.eigenvectors(): After diagonalization\n"
193 // << eigenSolver.eigenvectors());
194
195 // {
196 eigEnergy = eigenSolver.eigenvalues();
197 EnergyRange = eigEnergy[eigEnergy.size() - 1] - eigEnergy[0];
198 groundEnergy = eigEnergy[0];
199 // Normalize eigenenergies
200 std::for_each(eigEnergy.begin(), eigEnergy.end(),
201 [&](auto& x) { x = (x - groundEnergy) / EnergyRange; });
202 debug_print("eigEnergy\n" << eigEnergy);
203
204 MicroCanonicalAverage const MCaverage(eigEnergy, shellWidth);
205
206 temp_t = getETtime();
207 std::cout << "Sample No. " << repetition << ", L = " << L << std::endl;
208 for(int opRep = opRepMin; opRep <= opRepMax; ++opRep) {
209 for(int m = mMin; m <= mMax; ++m) {
210 std::cout << "opRep=" << opRep << ", m=" << m << std::endl;
211 Eigen::MatrixX<Complex_t<double>> testOp
212 = transSector.basis().adjoint() * GRME[m]() * transSector.basis();
213
214 calculateETHmeasure(colVec, eigenSolver.eigenvectors(), transSector,
215 mBodyOperatorSpace(m, H_tot), MCaverage);
216 ETHmeasure.col(m) += colVec;
217 }
218 temp_t = getETtime();
219 {
220 debug_print("# Writing results to a file.");
221 std::stringstream buff("");
222 buff << "/OpSample_No" << opRep;
223 std::string filename(outDirName + buff.str());
224 if(!std::filesystem::exists(filename)
225 && !std::filesystem::create_directories(filename)) {
226 std::cerr << "Error: Failed to create directories: " << filename
227 << std::endl;
228 std::exit(EXIT_FAILURE);
229 };
230
231 buff << "/StrongETHMeasure" << PRECISION << "_N" << L << ".txt";
232 filename += buff.str();
233 OutFs.open(filename);
234 if(!OutFs) {
235 std::cerr << "Error: Can't open a file (" << filename << ")" << std::endl;
236 std::exit(EXIT_FAILURE);
237 }
238 OutFs << std::right << std::showpos << std::scientific << std::setprecision(6);
239 OutFs << "# energyRange= " << EnergyRange << "\n"
240 << "# groundEnergy= " << groundEnergy << "\n"
241 << "# shellWidth= " << shellWidth << "\n"
242 << "# diffWithTheory= " << diff << "\n"
243 << "# 1.(Normalized energy) 2.(dimShell) 2.(Distinguishability measure) "
244 << "\n\n";
245 for(auto j = 0; j < eigEnergy.size(); ++j) {
246 OutFs << eigEnergy[j] << " " << MCaverage.dimShell(j);
247 for(auto m = 1; m <= L; ++m) { OutFs << " " << ETHmeasure(j, m); }
248 OutFs << std::endl;
249 }
250 OutFs.close();
251 }
252 T_IO += getETtime() - temp_t;
253
254 std::cout << std::endl;
255 }
256 T_post += getETtime() - temp_t;
257
258 // std::cout << std::endl;
259 // theorySum = Eigen::VectorXd::Ones(MCaverage.dim())
260 // - MCaverage.dimShell().cast<double>().cwiseInverse();
261 // double maxDiff = (ETHmeasure.rowwise().sum() - theorySum).maxCoeff();
262 // if(maxDiff > 1.0e-4) {
263 // std::cout << "ETHmeasure.rowwise().sum():\n"
264 // << ETHmeasure.rowwise().sum() << "\n"
265 // << std::endl;
266 // std::cout << "theorySum:\n" << theorySum << "\n" << std::endl;
267 // std::cout << "ETHmeasure:\n" << ETHmeasure << "\n" << std::endl;
268 // std::cerr << "Error : maxDiff = " << maxDiff << " is too large." << std::endl;
269 // }
270 }
271
272 if(repetition % 10 == 9 || repetition == repMax) {
273 t_int = end;
274 end = getETtime();
275 std::cerr << "(total=" << std::setw(6) << repetition + 1
276 << "): timeINT=" << std::setprecision(6) << std::setw(8) << (end - t_int)
277 << ", timeTOT=" << std::setprecision(6) << std::setw(8) << (end - start)
278 << ", T_construct=" << std::setprecision(6) << std::setw(10) << T_pre << "("
279 << std::setprecision(1) << 100 * T_pre / (end - start) << "%)"
280 << ", T_diag=" << std::setprecision(6) << std::setw(8) << T_diag << "("
281 << std::setprecision(1) << 100 * T_diag / (end - start) << "%)"
282 << ", T_process=" << std::setprecision(6) << std::setw(8) << T_post << "("
283 << std::setprecision(1) << 100 * T_post / (end - start) << "%)"
284 << ", T_IO=" << std::setprecision(6) << std::setw(8) << T_IO << "("
285 << std::setprecision(1) << 100 * T_IO / (end - start) << "%)" << std::endl;
286 }
287 }
288 return EXIT_SUCCESS;
289}
double getETtime()
Definition EnergySpectrum.c:14
Definition ETHmeasure.hpp:133
Definition HilbertSpace.hpp:32
static MagmaController & getInstance()
Definition ObjectOnGPU_EigenMatrix_test.cu:14
Definition HilbertSpace.hpp:423
Definition MatrixUtils.hpp:20
Calculate the microcanonical averages with respect to a given sorted vector 'eigVal'.
Definition MicroCanonicalAverage.hpp:25
Definition ObjectOnGPU.cuh:149
Definition Ensemble_old.hpp:6
Translation invariant sector of a many-body Hilbert space.
Definition TransSector.hpp:19
Definition OperatorSpace.hpp:430
cuCHECK(cudaFuncGetAttributes(&attr, MatrixElementsInSector))
debug_print("# Determining GPU configuration.")
baseDirName
Definition setVariablesForEnsemble.cpp:50
Integer_t const repMin
Definition setVariablesForEnsemble.cpp:31
Integer_t const repMax
Definition setVariablesForEnsemble.cpp:32
std::stringstream buff("")