-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpinSpace.h
63 lines (56 loc) · 2.19 KB
/
SpinSpace.h
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
/*
Developed by Sandeep Sharma and Garnet K.-L. Chan, 2012
Copyright (c) 2012, Garnet K.-L. Chan
This program is integrated in Molpro with the permission of
Sandeep Sharma and Garnet K.-L. Chan
*/
#ifndef SPIN_SPACE_HEADER
#define SPIN_SPACE_HEADER
#include <boost/serialization/serialization.hpp>
#include <vector>
#include <iostream>
#include <fstream>
namespace SpinAdapted{
/// @brief `SpinSpace` is a wrapper class for the spin irrep.
///
/// In Sz symmetry, the irrep is 2*Sz. In SU(2) symmetry, the
/// irrep is 2*S. The behaviour is toggled between Sz and S2 symmetry by checking dmrg.spinAdapted().
///
/// `SpinSpace` defines addition of irreps in SU(2) symmetry
/// to return the Clebsch-Gordon series for S1+S2=|S1-S2|...S1+S2.
///
///
class SpinSpace
{
private:
friend class boost::serialization::access;
template<class Archive> void serialize(Archive & ar, const unsigned int version)
{
ar & irrep;
}
/// Integer representing 2*S or 2*Sz
int irrep;
public:
SpinSpace() : irrep(0) {}
explicit SpinSpace(int ir);
void SaveThreadSafe(std::ofstream& ofs) const {ofs.write( (char*)(&irrep), sizeof(irrep));}
void LoadThreadSafe(std::ifstream& ifs) {ifs.read( (char*)(&irrep), sizeof(irrep));}
std::vector<SpinSpace> operator+=(SpinSpace rhs);
bool operator==(SpinSpace rhs) const;
bool operator!=(SpinSpace rhs) const;
bool operator<(SpinSpace rhs) const;
/// Adds integer irreps in lhs, rhs.
/// \return If S2 symmetry (`dmrg.spinAdapted()==true`), vector |S1-S2| ... S1+S2, else,
/// vector of length 1 containing Sz1+Sz2
friend std::vector<SpinSpace> operator+(SpinSpace lhs, SpinSpace rhs);
/// Negate irrep.
/// \return In Sz symmetry, -Sz; for S2 symmetry, returns same irrep S (i.e. does nothing,
/// since negative S has no meaning).
friend SpinSpace operator-(SpinSpace lhs);
void Save(std::ofstream &ofs);
void Load(std::ifstream &ifs);
friend std::ostream& operator<<(std::ostream& os, const SpinSpace s);
int getirrep() const ;
};
}
#endif