7#include <initializer_list>
11#include "utils/vec_clone.hpp"
19 class Bond_impl:
public intrusive_ptr_base<Bond_impl>{
26 std::vector< std::vector<cytnx_int64> > _qnums;
27 std::vector<Symmetry> _syms;
29 Bond_impl(): _type(bondType::BD_REG) {};
31 void Init(
const cytnx_uint64 &dim,
const bondType &bd_type=bondType::BD_REG,
const std::vector<std::vector<cytnx_int64> > &in_qnums = {},
const std::vector<Symmetry> &in_syms={});
34 bondType type()
const{
return this->_type;};
35 const std::vector<std::vector<cytnx_int64> >& qnums()
const{
return this->_qnums;}
36 std::vector<std::vector<cytnx_int64> >& qnums(){
return this->_qnums;}
39 const std::vector<Symmetry>& syms()
const{
return this->_syms;}
40 std::vector<Symmetry>& syms(){
return this->_syms;}
43 std::vector<std::vector<cytnx_int64> > qnums_clone()
const{
return this->_qnums;}
44 std::vector<Symmetry> syms_clone()
const{
return vec_clone(this->_syms);}
47 void set_type(
const bondType &new_bondType){
48 if((this->_type != BD_REG) && (new_bondType == BD_REG)){
49 cytnx_error_msg(this->_qnums.size(),
"[ERROR] cannot change type to BD_REG for a symmetry bond.%s",
"\n");
51 this->_type = new_bondType;
55 if(this->_type != BD_REG){
56 cytnx_error_msg(this->_qnums.size(),
"[ERROR] cannot clear type for a symmetry bond.%s",
"\n");
58 this->_type = bondType::BD_REG;
62 boost::intrusive_ptr<Bond_impl> clone(){
63 boost::intrusive_ptr<Bond_impl> out(
new Bond_impl());
64 out->_dim = this->dim();
65 out->_type = this->type();
66 out->_qnums = this->qnums_clone();
67 out->_syms = this->syms_clone();
71 void combineBond_(
const boost::intrusive_ptr<Bond_impl> &bd_in);
74 boost::intrusive_ptr<Bond_impl> combineBond(
const boost::intrusive_ptr<Bond_impl> &bd_in){
75 boost::intrusive_ptr<Bond_impl> out = this->clone();
76 out->combineBond_(bd_in);
81 std::vector<std::vector<cytnx_int64> > getUniqueQnums(std::vector<cytnx_uint64> &counts,
const bool &return_counts);
84 cytnx_uint64 getDegeneracy(
const std::vector<cytnx_int64> &qnum,
const bool &return_indices,std::vector<cytnx_uint64> &indices);
87 std::vector<std::vector<cytnx_int64> > calc_reverse_qnums();
97 boost::intrusive_ptr<Bond_impl> _impl;
98 Bond(): _impl(
new Bond_impl()){};
99 Bond(
const Bond&rhs){this->_impl = rhs._impl;}
100 Bond& operator=(
const Bond &rhs){this->_impl = rhs._impl;
return *
this;}
104 this->_impl->Init(
dim,bd_type,in_qnums,in_syms);
133 this->_impl->Init(
dim,bd_type,in_qnums,in_syms);
150 const std::vector<std::vector<cytnx_int64> >&
qnums()
const{
return this->_impl->qnums();};
151 std::vector<std::vector<cytnx_int64> >&
qnums(){
return this->_impl->qnums();};
159 std::vector<std::vector<cytnx_int64> >
qnums_clone()
const{
return this->_impl->qnums_clone();};
182 const std::vector<Symmetry>&
syms()
const{
return this->_impl->syms();};
183 std::vector<Symmetry>&
syms(){
return this->_impl->syms();};
191 std::vector<Symmetry>
syms_clone()
const{
return this->_impl->syms_clone();};
202 this->_impl->
set_type(new_bondType);
211 this->_impl->clear_type();
230 out._impl = this->_impl->
clone();
250 this->_impl->combineBond_(bd_in._impl);
322 std::vector<std::vector<cytnx_int64> >
getUniqueQnums(std::vector<cytnx_uint64> &counts){
323 return this->_impl->getUniqueQnums(counts,
true);
326 std::vector<cytnx_uint64> tmp;
327 return this->_impl->getUniqueQnums(tmp,
false);
339 std::vector<cytnx_uint64> tmp;
340 return this->_impl->getDegeneracy(qnum,
false,tmp);
344 return this->_impl->getDegeneracy(qnum,
true,indices);
348 return this->_impl->calc_reverse_qnums();
352 void Save(
const std::string &fname)
const;
353 void Save(
const char* fname)
const;
359 void _Save(std::fstream &f)
const;
360 void _Load(std::fstream &f);
380 std::ostream&
operator<<(std::ostream &os,
const Bond &bin);
the object contains auxiliary properties for each Tensor rank (bond)
Definition Bond.hpp:94
std::vector< std::vector< cytnx_int64 > > & qnums()
Definition Bond.hpp:151
Bond & set_type(const bondType &new_bondType)
change the tag-type of the instance Bond
Definition Bond.hpp:201
cytnx_uint64 getDegeneracy(const std::vector< cytnx_int64 > &qnum) const
return the degeneracy of specify qnum set.
Definition Bond.hpp:338
void combineBonds_(const std::vector< Bond > &bds)
combine multiple input bonds with self, inplacely
Definition Bond.hpp:311
Bond & operator*=(const Bond &rhs)
Definition Bond.hpp:370
const std::vector< Symmetry > & syms() const
return the vector of symmetry objects by reference.
Definition Bond.hpp:182
std::vector< std::vector< cytnx_int64 > > qnums_clone() const
return copy of the current quantum number set(s)
Definition Bond.hpp:159
Bond combineBonds(const std::vector< Bond > &bds)
combine multiple input bonds with self, and return a new combined Bond instance.
Definition Bond.hpp:289
static cytnx::Bond Load(const std::string &fname)
Definition Bond.cpp:237
Bond operator*(const Bond &rhs) const
Definition Bond.hpp:366
void clear_type()
change the tag-type to the default value BD_REG
Definition Bond.hpp:210
void Init(const cytnx_uint64 &dim, const bondType &bd_type=bondType::BD_REG, const std::vector< std::vector< cytnx_int64 > > &in_qnums={}, const std::vector< Symmetry > &in_syms={})
init a bond object
Definition Bond.hpp:132
Bond(const cytnx_uint64 &dim, const bondType &bd_type=bondType::BD_REG, const std::vector< std::vector< cytnx_int64 > > &in_qnums={}, const std::vector< Symmetry > &in_syms={})
Definition Bond.hpp:103
bondType type() const
return the current tag type
Definition Bond.hpp:141
Bond clone() const
return a copy of the instance Bond
Definition Bond.hpp:228
cytnx_uint64 getDegeneracy(const std::vector< cytnx_int64 > &qnum, std::vector< cytnx_uint64 > &indices) const
Definition Bond.hpp:342
std::vector< Symmetry > syms_clone() const
return copy of the vector of symmetry objects.
Definition Bond.hpp:191
Bond combineBond(const Bond &bd_in) const
combine the input bond with self, and return a new combined Bond instance.
Definition Bond.hpp:268
cytnx_uint64 dim() const
return the dimension of the bond
Definition Bond.hpp:166
std::vector< std::vector< cytnx_int64 > > getUniqueQnums()
Definition Bond.hpp:325
const std::vector< std::vector< cytnx_int64 > > & qnums() const
return the current quantum number set(s) by reference
Definition Bond.hpp:150
std::vector< Symmetry > & syms()
Definition Bond.hpp:183
void combineBond_(const Bond &bd_in)
combine the input bond with self, inplacely
Definition Bond.hpp:249
cytnx_uint32 Nsym() const
return the number of symmetries
Definition Bond.hpp:173
std::vector< std::vector< cytnx_int64 > > getUniqueQnums(std::vector< cytnx_uint64 > &counts)
return a sorted qnum sets by removing all the duplicate qnum sets.
Definition Bond.hpp:322
std::vector< std::vector< cytnx_int64 > > calc_reverse_qnums()
Definition Bond.hpp:347
bool operator!=(const Bond &rhs) const
Definition Bond.cpp:212
void Save(const std::string &fname) const
Definition Bond.cpp:217
bool operator==(const Bond &rhs) const
Definition Bond.cpp:203
#define cytnx_error_msg(is_true, format,...)
Definition cytnx_error.hpp:18
Definition Accessor.hpp:12
uint32_t cytnx_uint32
Definition Type.hpp:23
std::ostream & operator<<(std::ostream &os, const Scalar &in)
Definition Scalar.cpp:14
uint64_t cytnx_uint64
Definition Type.hpp:22
bondType
Definition Bond.hpp:13
@ BD_REG
Definition Bond.hpp:16
@ BD_BRA
Definition Bond.hpp:15
@ BD_KET
Definition Bond.hpp:14