examples/operator

examples/Operator/src/main.cpp

 1#include <iostream>
 2
 3#include "Operator.h"
 4
 5/* Maximal system size */
 6#define MaxSites 128
 7
 8/* Hilbert space dimension */
 9#define Q 2
10
11/* Definition of the State class */
12using State=danceq::internal::State<MaxSites,Q>;
13
14/* Definition of the Basis class */
15using Basis=danceq::internal::Basis<State>;
16
17/* Definition of the Operator class from the Basis class */
18using Operator=danceq::internal::Operator<Basis,double>;
19
20/* Definition of the Operator class from the State class */
21using Operator_full=danceq::internal::Operator<State,double>;
22
23
24int main(int argc, char *argv[]) {
25
26	/* Number of particles */
27	uint64_t n = 1;
28
29	/* System size */
30	uint64_t L = 4;
31
32	/* number of subsystems */
33	uint64_t Npart = 3;
34	
35	/* Particle number, system size and number of subsystem can be edited at run time: ./main -n 5 -L 10 -Npart 4 */
36	if (argc > 1){
37		for(uint32_t i = 1; i < argc; ++i){ 
38			std::string arg_val(argv[i]);
39			bool input = true;
40			if(arg_val == "-n" and i < argc - 1){
41				n = static_cast<uint64_t>(std::stoi(argv[i+1]));
42				input = false;i++;
43			}
44			if(arg_val == "-L" and i < argc - 1){
45				L = static_cast<uint64_t>(std::stoi(argv[i+1]));
46				input = false;i++;
47			}
48			if(input){
49				std::cout << "[main] - Unknown option at input variable " << i << " : " << arg_val << std::endl;
50			}
51		}
52	}
53
54
55	std::cout << "[main] - L = " << L << std::endl;
56	std::cout << "[main] - n = " << n << std::endl;
57
58	/* Operator class */
59	Operator H(L,n);
60
61	uint64_t dim = H.get_dim();
62	std::cout << "[main] - dim = " << dim << std::endl;
63
64	/* Heisenberg model with PBC */
65	for(uint64_t i = 0; i < L; i++){
66		H.add_operator(.5, {i,(i+1)%L}, {"S+","S-"});
67		H.add_operator(.5, {i,(i+1)%L}, {"S-","S+"});
68		H.add_operator(1., {i,(i+1)%L}, {"Sz","Sz"});
69	}
70
71	/* Printing information of the Hamiltonian */
72	H.info();
73
74	std::cout << "[main] - generating dense matrix ... ";
75	auto H_dense = H.create_DenseMatrix();
76	std::cout << "done" << std::endl;
77	for(uint64_t i = 0; i < dim; i++){
78		std::cout << "[main] - ";
79		for(uint64_t j = 0; j < dim; j++){
80			std::cout << H_dense[i][j] << " ";
81		}
82		std::cout << std::endl;
83	}
84
85
86	std::cout << "[main] - generating sparse matrix ... ";
87	auto H_sparse = H.create_SparseMatrix();
88	std::cout << "done" << std::endl;
89	H_sparse.print();
90
91    return 0;
92}