Xped
Loading...
Searching...
No Matches
Heisenberg.hpp
Go to the documentation of this file.
1#ifndef XPED_PEPS_HEISENBERG_HPP_
2#define XPED_PEPS_HEISENBERG_HPP_
3
4#include <map>
5#include <string>
6
7#include <highfive/H5File.hpp>
8
14#include "Xped/Util/Param.hpp"
15
16namespace Xped {
17
18/* gs energy:
19 square: E/N = -0.66944
20 triang: E/N = −0.5445
21 j1j2: E/N =
22*/
23template <typename Symmetry>
24class Heisenberg : public TwoSiteObservable<double, Symmetry>
25{
26public:
27 Heisenberg(std::map<std::string, Param>& params_in, const Pattern& pat_in, Opts::Bond bond = Opts::Bond::H | Opts::Bond::V)
28 : TwoSiteObservable<double, Symmetry>(pat_in, bond)
29 , params(params_in)
30 , pat(pat_in)
31 {
32 if constexpr(std::is_same_v<Symmetry, Sym::SU2<Sym::SpinSU2>>) {
33 used_params = {"J"};
34 } else {
35 used_params = {"Jxy", "Jz"};
36 }
37 if((bond & Opts::Bond::D1) == Opts::Bond::D1 or (bond & Opts::Bond::D2) == Opts::Bond::D2) { used_params.push_back("J2"); }
38
39 B = SpinBase<Symmetry>(1, 2);
41 if constexpr(std::is_same_v<Symmetry, Sym::SU2<Sym::SpinSU2>>) {
42 gate = params["J"].get<double>() * (std::sqrt(3.) * tprod(B.Sdag(0), B.S(0))).eval();
43 } else if constexpr(Symmetry::ALL_ABELIAN) {
44 gate = params["Jz"].get<double>() * tprod(B.Sz(), B.Sz()) +
45 0.5 * params["Jxy"].get<double>() * (tprod(B.Sp(), B.Sm()) + tprod(B.Sm(), B.Sp()));
46 } else {
47 assert(false and "Symmetry is not supported in Heisenberg model.");
48 }
49
51 for(auto& t : this->data_h) { t = gate; }
52 }
54 for(auto& t : this->data_v) { t = gate; }
55 }
57 for(auto& t : this->data_d1) { t = params["J2"].get<double>() * gate; }
58 }
60 for(auto& t : this->data_d2) { t = params["J2"].get<double>() * gate; }
61 }
62 }
63
64 virtual void setDefaultObs() override
65 {
66 if constexpr(std::is_same_v<Symmetry, Sym::SU2<Sym::SpinSU2>>) {
67 auto SS = std::make_unique<Xped::TwoSiteObservable<double, Symmetry>>(
69 for(auto& t : SS->data_h) { t = std::sqrt(3.) * Xped::tprod(B.Sdag(), B.S()); }
70 for(auto& t : SS->data_v) { t = std::sqrt(3.) * Xped::tprod(B.Sdag(), B.S()); }
71 for(auto& t : SS->data_d1) { t = std::sqrt(3.) * Xped::tprod(B.Sdag(), B.S()); }
72 for(auto& t : SS->data_d2) { t = std::sqrt(3.) * Xped::tprod(B.Sdag(), B.S()); }
73 obs.push_back(std::move(SS));
74
75 } else if constexpr(Symmetry::ALL_ABELIAN) {
76 auto Sz = std::make_unique<Xped::OneSiteObservable<double, Symmetry>>(pat, "Sz");
77 for(auto& t : Sz->data) { t = B.Sz().data.template trim<2>(); }
78 obs.push_back(std::move(Sz));
79 if constexpr(Symmetry::ALL_IS_TRIVIAL) {
80 auto Sx = std::make_unique<Xped::OneSiteObservable<double, Symmetry>>(pat, "Sx");
81 for(auto& t : Sx->data) { t = B.Sx().data.template trim<2>(); }
82 obs.push_back(std::move(Sx));
83 }
84 auto SzSz = std::make_unique<Xped::TwoSiteObservable<double, Symmetry>>(
86 for(auto& t : SzSz->data_h) { t = Xped::tprod(B.Sz(), B.Sz()); }
87 for(auto& t : SzSz->data_v) { t = Xped::tprod(B.Sz(), B.Sz()); }
88 for(auto& t : SzSz->data_d1) { t = Xped::tprod(B.Sz(), B.Sz()); }
89 for(auto& t : SzSz->data_d2) { t = Xped::tprod(B.Sz(), B.Sz()); }
90 obs.push_back(std::move(SzSz));
91 if constexpr(not Symmetry::ANY_IS_SPIN) {
92 auto SxSx = std::make_unique<TwoSiteObservable<double, Symmetry>>(
94 for(auto& t : SxSx->data_h) { t = tprod(B.Sx(), B.Sx()); }
95 for(auto& t : SxSx->data_v) { t = tprod(B.Sx(), B.Sx()); }
96 for(auto& t : SxSx->data_d1) { t = tprod(B.Sx(), B.Sx()); }
97 for(auto& t : SxSx->data_d2) { t = tprod(B.Sx(), B.Sx()); }
98 obs.push_back(std::move(SxSx));
99 auto Sy = std::make_unique<Xped::OneSiteObservable<std::complex<double>, Symmetry>>(pat, "Sy");
100 for(auto& t : Sy->data) { t = B.Sy().data.template trim<2>(); }
101 obs.push_back(std::move(Sy));
102 }
103 }
104 }
105
106 virtual std::string file_name() const override { return internal::create_filename("Heisenberg", params, used_params); }
107
108 virtual std::string format() const override
109 {
110 return internal::format_params(fmt::format("Heisenberg[sym={}]", Symmetry::name()), params, used_params);
111 }
112
113 virtual void computeObs(XPED_CONST CTM<double, Symmetry, 2, false, Opts::CTMCheckpoint{}>& env) override
114 {
115 for(auto& ob : obs) {
116 if(auto* one = dynamic_cast<OneSiteObservable<double, Symmetry>*>(ob.get()); one != nullptr) { avg(env, *one); }
117 if(auto* one_c = dynamic_cast<OneSiteObservable<std::complex<double>, Symmetry>*>(ob.get()); one_c != nullptr) { avg(env, *one_c); }
118 if(auto* two = dynamic_cast<TwoSiteObservable<double, Symmetry>*>(ob.get()); two != nullptr) { avg(env, *two); }
119 }
120 }
121
122 virtual void computeObs(XPED_CONST CTM<std::complex<double>, Symmetry, 2, false, Opts::CTMCheckpoint{}>& env) override
123 {
124 for(auto& ob : obs) {
125 if(auto* one = dynamic_cast<OneSiteObservable<double, Symmetry>*>(ob.get()); one != nullptr) { avg(env, *one); }
126 if(auto* one_c = dynamic_cast<OneSiteObservable<std::complex<double>, Symmetry>*>(ob.get()); one_c != nullptr) { avg(env, *one_c); }
127 if(auto* two = dynamic_cast<TwoSiteObservable<double, Symmetry>*>(ob.get()); two != nullptr) { avg(env, *two); }
128 }
129 }
130
131 virtual void computeObs(XPED_CONST CTM<double, Symmetry, 1, false, Opts::CTMCheckpoint{}>& env) override
132 {
133 for(auto& ob : obs) {
134 if(auto* one = dynamic_cast<OneSiteObservable<double, Symmetry>*>(ob.get()); one != nullptr) { avg(env, *one); }
135 if(auto* one_c = dynamic_cast<OneSiteObservable<std::complex<double>, Symmetry>*>(ob.get()); one_c != nullptr) { avg(env, *one_c); }
136 if(auto* two = dynamic_cast<TwoSiteObservable<double, Symmetry>*>(ob.get()); two != nullptr) { avg(env, *two); }
137 }
138 }
139
140 virtual std::string getObsString(const std::string& offset) const override
141 {
142 std::string out;
143 for(const auto& ob : obs) {
144 out.append(ob->getResString(offset));
145 if(&ob != &obs.back()) { out.push_back('\n'); }
146 }
147 return out;
148 }
149
150 virtual void obsToFile(HighFive::File& file, const std::string& root = "/") const override
151 {
152 for(const auto& ob : obs) { ob->toFile(file, root); }
153 }
154
155 std::map<std::string, Param> params;
157 std::vector<std::string> used_params;
159 std::vector<std::unique_ptr<ObservableBase>> obs;
160};
161
162} // namespace Xped
163#endif
Definition: CTM.hpp:62
Definition: Heisenberg.hpp:25
Heisenberg(std::map< std::string, Param > &params_in, const Pattern &pat_in, Opts::Bond bond=Opts::Bond::H|Opts::Bond::V)
Definition: Heisenberg.hpp:27
virtual void computeObs(XPED_CONST CTM< double, Symmetry, 1, false, Opts::CTMCheckpoint{}> &env) override
Definition: Heisenberg.hpp:131
virtual void computeObs(XPED_CONST CTM< double, Symmetry, 2, false, Opts::CTMCheckpoint{}> &env) override
Definition: Heisenberg.hpp:113
Pattern pat
Definition: Heisenberg.hpp:156
virtual std::string getObsString(const std::string &offset) const override
Definition: Heisenberg.hpp:140
virtual void obsToFile(HighFive::File &file, const std::string &root="/") const override
Definition: Heisenberg.hpp:150
SpinBase< Symmetry > B
Definition: Heisenberg.hpp:158
virtual void setDefaultObs() override
Definition: Heisenberg.hpp:64
virtual void computeObs(XPED_CONST CTM< std::complex< double >, Symmetry, 2, false, Opts::CTMCheckpoint{}> &env) override
Definition: Heisenberg.hpp:122
virtual std::string file_name() const override
Definition: Heisenberg.hpp:106
std::vector< std::string > used_params
Definition: Heisenberg.hpp:157
virtual std::string format() const override
Definition: Heisenberg.hpp:108
std::map< std::string, Param > params
Definition: Heisenberg.hpp:155
std::vector< std::unique_ptr< ObservableBase > > obs
Definition: Heisenberg.hpp:159
Definition: SpinBase.hpp:23
std::enable_if< Dummy::IS_SPIN_SU2(), OperatorType >::type S(std::size_t orbital=0) const
Definition: SpinBase.hpp:387
std::enable_if<!Dummy::IS_SPIN_SU2(), OperatorType >::type Sz(std::size_t orbital=0) const
Definition: SpinBase.hpp:450
std::enable_if< Dummy::NO_SPIN_SYM(), OperatorTypeC >::type Sy(std::size_t orbital=0) const
Definition: SpinBase.hpp:481
std::enable_if< Dummy::NO_SPIN_SYM(), OperatorType >::type Sx(std::size_t orbital=0) const
Definition: SpinBase.hpp:471
std::enable_if<!Dummy::IS_SPIN_SU2(), OperatorType >::type Sp(std::size_t orbital=0) const
Definition: SpinBase.hpp:457
std::enable_if< Dummy::IS_SPIN_SU2(), OperatorType >::type Sdag(std::size_t orbital=0) const
Definition: SpinBase.hpp:394
std::enable_if<!Dummy::IS_SPIN_SU2(), OperatorType >::type Sm(std::size_t orbital=0) const
Definition: SpinBase.hpp:464
Definition: Tensor.hpp:40
Bond
Definition: Bonds.hpp:10
std::string format_params(const std::string &name, const std::map< std::string, Param > &params, const std::vector< std::string > &used_params)
Definition: Helpers.hpp:12
std::string create_filename(const std::string &name, const std::map< std::string, Param > &params, const std::vector< std::string > &used_params)
Definition: Helpers.hpp:26
Definition: bench.cpp:62
TMatrix< std::conditional_t< ENABLE_AD, stan::math::var, typename OneSiteObservable< OpScalar, Symmetry, HERMITIAN >::ObsScalar > > avg(XPED_CONST CTM< Scalar, Symmetry, TRank, ENABLE_AD, CPOpts > &env, OneSiteObservable< OpScalar, Symmetry, HERMITIAN > &op)
Definition: LinearAlgebra.cpp:11
Tensor< Scalar, 2, 2, Symmetry, false > tprod(XPED_CONST SiteOperator< Scalar, Symmetry > &O1, XPED_CONST SiteOperator< Scalar, Symmetry > &O2, bool ADD_TWIST=false, bool REVERSE_ORDER=false)
Definition: SiteOperator.hpp:150
Definition: OneSiteObservable.hpp:21
Definition: CTMOpts.hpp:96
Definition: Pattern.hpp:18
Definition: TwoSiteObservable.hpp:22
TMatrix< Tensor< double, 2, 2, Symmetry, false > > data_h
Definition: TwoSiteObservable.hpp:287
TMatrix< Tensor< double, 2, 2, Symmetry, false > > data_v
Definition: TwoSiteObservable.hpp:288
TMatrix< Tensor< double, 2, 2, Symmetry, false > > data_d1
Definition: TwoSiteObservable.hpp:289
Opts::Bond bond
Definition: TwoSiteObservable.hpp:295
TMatrix< Tensor< double, 2, 2, Symmetry, false > > data_d2
Definition: TwoSiteObservable.hpp:290