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/matrix_util.hpp"
9#include "Headers/spin_int.hpp"
10#include "Headers/mersenne_twister.hpp"
11#include <iostream>
12#include <sysexits.h>
13#include <cmath>
14
15static inline bool Initialize(int const argc, char const*const* argv, int const Nargs_common) { return true; }
16static inline bool Finalize(int argc, char** argv) { return true; }
17
18static inline Integer_t SectorDimension(TransSector const& Sector) {
19 return Sector.dim();
20}
21
22static inline void generateLocal_h(matrix<Complex_t>& mat, Integer_t const d_lmat, Integer_t const seed){
23 if(seed >= 0) {
24 init_genrand(seed);
25 std::cout << "# init_genrand(" << seed << ")\n";
26 }
27 // RandomMatrix_GUE(mat, d_lmat);
28
29 mat.at(0,0) = -1.1217*ComplexOne<>;
30 mat.at(1,0) = 0.0*ComplexOne<>; mat.at(1,1) = -0.4034*ComplexOne<>;
31 mat.at(2,0) = 0.0*ComplexOne<>; mat.at(2,1) = 0.2730*ComplexOne<>; mat.at(2,2) = -0.4034*ComplexOne<>;
32 mat.at(3,0) = -0.1222*ComplexOne<>; mat.at(3,1) = 0.0*ComplexOne<>; mat.at(3,2) = 0.0*ComplexOne<>; mat.at(3,3) = -1.1217*ComplexOne<>;
33 for(int i = 0;i < 4; ++i) for(int j = i+1;j < 4; ++j) mat.at(i,j) = conj(mat.at(j,i));
34 mat.print(d_lmat,d_lmat);
35};
36
37static inline void generateLocal_op(matrix<Complex_t>& mat, Integer_t const d_lmat, Integer_t const seed){
38 if(seed >= 0) init_genrand(seed);
39 RandomMatrix_GUE(mat, d_lmat);
40};
41
42static inline void MatrixElementsInSector(matrix<Complex_t>& matTot, matrix<Complex_t> const& matLoc, Integer_t const numLoc, TransSector const& Sector);
43
44static inline Integer_t constructGlobal_h(matrix<Complex_t>& global, matrix<Complex_t> const& local, Integer_t const numLoc, TransSector const& Sector, void* GPUconf = nullptr){
45 MatrixElementsInSector(global, local, numLoc, Sector);
46 #ifndef NDEBUG
47 if(Sector.N() <= 4) {
48 Integer_t d_loch = pow(Sector.dloc(), numLoc);
49 std::cout << "n=" << Sector.N() << "\n";
50 local.print(d_loch,d_loch);
51 global.print(Sector.dim(),Sector.dim());
52 std::cout << "\n" << std::endl;
53 }
54 #endif
55 return Sector.dim();
56};
57
58static inline Integer_t constructGlobal_op(matrix<Complex_t>& global, matrix<Complex_t> const& local, Integer_t const numLoc, TransSector const& Sector, void* GPUconf = nullptr){
59 return constructGlobal_h(global, local, numLoc, Sector);
60};
61
62static inline void MatrixElementsInSector(matrix<Complex_t>& matTot, matrix<Complex_t> const& matLoc, Integer_t const numLoc, TransSector const& Sector) {
63 std::fill(matTot.begin(), matTot.end(), ComplexZero<>);
64
65 double theta;
66 Integer_t Id1, Id2, locId1, locId2;
67 Integer_t const dmatLoc = (Integer_t)pow(Sector.dloc(), numLoc);
68
69 #pragma omp parallel for schedule(dynamic, 1) private(Id1, Id2, locId1, locId2, theta)
70 for(int idx = 0;idx < Sector.dim(); ++idx) for(int idy = 0;idy <= idx; ++idy) {
71 for(int trans1 = 0;trans1 < Sector.periodicity(idx); ++trans1) {
72 Id1 = transSpin(Sector.representative(idx),trans1,Sector.dloc(),Sector.N());
73 locId1 = Id1%dmatLoc;
74 for(int trans2 = 0;trans2 < Sector.periodicity(idy); ++trans2) {
75 Id2 = transSpin(Sector.representative(idy),trans2,Sector.dloc(),Sector.N());
76 locId2 = Id2%dmatLoc;
77 if(Id1/dmatLoc != Id2/dmatLoc) continue;
78 theta = 2.0*M_PI*Sector.momentum()*(trans2-trans1)/(Real_t)Sector.N();
79 matTot.at(idx,idy) += matLoc.at(locId1,locId2) *std::exp(I<>*theta);
80 }
81 }
82 matTot.at(idx,idy) /= sqrt( (double)Sector.periodicity(idx)*Sector.periodicity(idy) );
83 matTot.at(idy,idx) = conj(matTot.at(idx,idy));
84 }
85}
86
87#endif
__global__ void MatrixElementsInSector(void)
Definition generateRM.cuh:61
std::vector< TransSector > Sector(n_max+1)
Translation invariant sector of a many-body Hilbert space.
Definition TransSector.hpp:19
GPUconfig GPUconf(dim3(nBlock, nBlock, 1), dim3(nThread, nThread, 1), 0, queue)
double Real_t
Definition mytypes.hpp:37
MKL_INT Integer_t
Definition mytypes.hpp:359