StatMech
Loading...
Searching...
No Matches
generateRM.hpp
Go to the documentation of this file.
1// Generate a random matrix used by all programs in this directory
2#ifndef GENERATE_RM
3#define GENERATE_RM
4#define _USE_MATH_DEFINES
5
6#include "Headers/mytypes.hpp"
7#include "Headers/LocalRandomMatrix.hpp"
8#include "Headers/translation.hpp"
9#include "Headers/mersenne_twister.hpp"
10#include "Headers/mydebug.hpp"
11#include <iostream>
12#include <cassert>
13#include <sysexits.h>
14#include <cmath>
15
16#define RANDTYPE argv[6] << argv[7] << "_"
17
18constexpr char USAGE_sp[] = "";
19constexpr int Nargs_sp = 0;
20
21matrix<double> prefactor;
22static inline bool Initialize(int const argc, char const*const* argv, int const Nargs_common) {
23 return true;
24}
25static inline bool Finalize(int argc, char** argv) {
26 return true;
27}
28
29static inline void generateLocal_h(matrix<Complex_t<double>>& mat, Integer_t const d_lmat, Integer_t const seed){
30 if(seed >= 0) {
31 init_genrand(seed);
32 std::cout << "# init_genrand(" << seed << ")\n";
33 }
34 // std::fill(mat.begin(), mat.end(), DoubleComplexZero);
35 // mat.at(0,0) = sqrt(2)*Gaussian();
36 // mat.at(0,1) = Complex_t<double>(Gaussian(),Gaussian());
37 // mat.at(0,2) = mat.at(0,1)
38 // mat.at(0,3) = Complex_t<double>(Gaussian(),Gaussian());
39 // mat.at(1,1) = sqrt(2)*Gaussian(); // = (2,2)
40 // mat.at(1,2) = Complex_t<double>(Gaussian(),Gaussian()); // = (2,1)
41 // mat.at(1,3) = Complex_t<double>(Gaussian(),Gaussian()); // = (2.3)
42 // mat.at(2,2) = mat.at(1,1);
43 // mat.at(2,3) = mat.at(1,3);
44 // mat.at(3,3) = sqrt(2)*Gaussian();
45
46 if(d_lmat != 4) {
47 std::cerr << "Error: Currently, only two-body operators on spin-1/2 chain is implemented." << std::endl;
48 std::exit(1);
49 }
50 RandomMatrix_GUE(mat, d_lmat);
51 // mat.at(0,0) = mat.at(0,0);
52 mat.at(0,1) = (mat.at(0,1)+mat.at(0,2))/2.0;
53 mat.at(0,2) = mat.at(0,1);
54 // mat.at(0,3) = mat.at(0,3);
55 mat.at(1,1) = (mat.at(1,1)+mat.at(2,2))/2.0;
56 mat.at(1,2) = (mat.at(1,2)+mat.at(2,1))/2.0;
57 mat.at(1,3) = (mat.at(1,3)+mat.at(2,3))/2.0;
58 mat.at(2,2) = mat.at(1,1);
59 mat.at(2,3) = mat.at(1,3);
60 // mat.at(3,3) = mat.at(3,3);
61
62 for(int i = 0;i < 4; ++i) for(int j = 0;j < i; ++j) {
63 mat.at(i,j) = conj(mat.at(j,i));
64 }
65
66};
67
68static inline void generateLocal_op(matrix<Complex_t<double>>& mat, Integer_t const d_lmat, Integer_t const seed){
69 generateLocal_h(mat, d_lmat, seed);
70};
71
72static inline Integer_t constructGlobal_h(matrix<Complex_t<double>>& global, const matrix<Complex_t<double>>& local, double const s, TransSector const Sector) {
73 Integer_t const imax = (Integer_t)(2*s);
74 double const n = Sector.N()/2.0;
75 double m;
76
77 std::fill(global.begin(), global.end(), DoubleComplexZero);
78
79 // #pragma omp parallel for private(m,n,s)
80 for(Integer_t i = 0;i <= imax; ++i) {
81 m = i-s;
82 if(i+2 <= imax) {
83 global.at(i+2,i) = sqrt((s-m)*(s-m-1)*(s+m+1)*(s+m+2)) *local.at(0,3); // 2nd degree
84 global.at(i,i+2) = conj(global.at(i+2,i));
85 }
86 if(i+1 <= imax) {
87 global.at(i+1,i) = 2*sqrt((s-m)*(s+m+1)) *( (n+m)*local.at(0,1) +(n-m-1)*local.at(1,3) ); // 2nd degree
88 global.at(i,i+1) = conj(global.at(i+1,i));
89 }
90 global.at(i,i) = 2.0*(s*(s+1) -m*m -n) *local.at(1,2) +2.0*(n*n-m*m)*local.at(1,1); // 2nd degree
91 global.at(i,i) += (n+m)*(n+m-1) *local.at(0,0) +(n-m)*(n-m-1) *local.at(3,3); // 2nd degree
92 }
93
94 #ifndef NDEBUG
95 if(imax <= 6) {
96 std::cout << "imax=" << imax << "\n";
97 local.print(4,4);
98 global.print(imax+1,imax+1);
99 std::cout << "\n" << std::endl;
100 }
101 #endif
102
103 return imax+1;
104};
105
106static inline Integer_t constructGlobal_op(matrix<Complex_t<double>>& global, const matrix<Complex_t<double>>& local, double const s, TransSector const Sector) {
107 return constructGlobal_h(global, local, s, Sector);
108};
109
110#endif
std::vector< Real_t * > prefactor
Definition generateRM.hpp:16
constexpr int Nargs_sp
Definition generateRM.hpp:19
std::string const USAGE_sp
Definition generateRM.hpp:17
std::vector< TransSector > Sector(n_max+1)
Definition mytypes.hpp:147
Translation invariant sector of a many-body Hilbert space.
Definition TransSector.hpp:19
MKL_INT Integer_t
Definition mytypes.hpp:359