7#include <initializer_list>
11#include "utils/vec_clone.hpp"
22 class Bond_impl:
public intrusive_ptr_base<Bond_impl>{
29 std::vector< std::vector<cytnx_int64> > _qnums;
30 std::vector<Symmetry> _syms;
32 Bond_impl(): _type(bondType::BD_REG) {};
34 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={});
37 bondType type()
const{
return this->_type;};
38 const std::vector<std::vector<cytnx_int64> >& qnums()
const{
return this->_qnums;}
39 std::vector<std::vector<cytnx_int64> >& qnums(){
return this->_qnums;}
42 const std::vector<Symmetry>& syms()
const{
return this->_syms;}
43 std::vector<Symmetry>& syms(){
return this->_syms;}
46 std::vector<std::vector<cytnx_int64> > qnums_clone()
const{
return this->_qnums;}
47 std::vector<Symmetry> syms_clone()
const{
return vec_clone(this->_syms);}
50 void set_type(
const bondType &new_bondType){
51 if((this->_type != BD_REG) && (new_bondType == BD_REG)){
52 cytnx_error_msg(this->_qnums.size(),
"[ERROR] cannot change type to BD_REG for a symmetry bond.%s",
"\n");
54 this->_type = new_bondType;
58 if(this->_type != BD_REG){
59 cytnx_error_msg(this->_qnums.size(),
"[ERROR] cannot clear type for a symmetry bond.%s",
"\n");
61 this->_type = bondType::BD_REG;
65 boost::intrusive_ptr<Bond_impl> clone(){
66 boost::intrusive_ptr<Bond_impl> out(
new Bond_impl());
67 out->_dim = this->dim();
68 out->_type = this->type();
69 out->_qnums = this->qnums_clone();
70 out->_syms = this->syms_clone();
74 void combineBond_(
const boost::intrusive_ptr<Bond_impl> &bd_in);
77 boost::intrusive_ptr<Bond_impl> combineBond(
const boost::intrusive_ptr<Bond_impl> &bd_in){
78 boost::intrusive_ptr<Bond_impl> out = this->clone();
79 out->combineBond_(bd_in);
84 std::vector<std::vector<cytnx_int64> > getUniqueQnums(std::vector<cytnx_uint64> &counts,
const bool &return_counts);
87 cytnx_uint64 getDegeneracy(
const std::vector<cytnx_int64> &qnum,
const bool &return_indices,std::vector<cytnx_uint64> &indices);
90 std::vector<std::vector<cytnx_int64> > calc_reverse_qnums();
100 boost::intrusive_ptr<Bond_impl> _impl;
101 Bond(): _impl(
new Bond_impl()){};
102 Bond(
const Bond&rhs){this->_impl = rhs._impl;}
103 Bond& operator=(
const Bond &rhs){this->_impl = rhs._impl;
return *
this;}
107 this->_impl->Init(
dim,bd_type,in_qnums,in_syms);
136 this->_impl->Init(
dim,bd_type,in_qnums,in_syms);
153 const std::vector<std::vector<cytnx_int64> >&
qnums()
const{
return this->_impl->qnums();};
154 std::vector<std::vector<cytnx_int64> >&
qnums(){
return this->_impl->qnums();};
162 std::vector<std::vector<cytnx_int64> >
qnums_clone()
const{
return this->_impl->qnums_clone();};
185 const std::vector<Symmetry>&
syms()
const{
return this->_impl->syms();};
186 std::vector<Symmetry>&
syms(){
return this->_impl->syms();};
194 std::vector<Symmetry>
syms_clone()
const{
return this->_impl->syms_clone();};
205 this->_impl->
set_type(new_bondType);
218 auto out = this->
clone();
219 out.set_type(new_bondType);
228 auto out = this->
clone();
229 out.set_type(
bondType(
int(out.type())*-1));
240 this->_impl->clear_type();
259 out._impl = this->_impl->
clone();
279 this->_impl->combineBond_(bd_in._impl);
351 std::vector<std::vector<cytnx_int64> >
getUniqueQnums(std::vector<cytnx_uint64> &counts){
352 return this->_impl->getUniqueQnums(counts,
true);
355 std::vector<cytnx_uint64> tmp;
356 return this->_impl->getUniqueQnums(tmp,
false);
368 std::vector<cytnx_uint64> tmp;
369 return this->_impl->getDegeneracy(qnum,
false,tmp);
373 return this->_impl->getDegeneracy(qnum,
true,indices);
377 return this->_impl->calc_reverse_qnums();
381 void Save(
const std::string &fname)
const;
382 void Save(
const char* fname)
const;
388 void _Save(std::fstream &f)
const;
389 void _Load(std::fstream &f);
409 std::ostream&
operator<<(std::ostream &os,
const Bond &bin);
the object contains auxiliary properties for each Tensor rank (bond)
Definition Bond.hpp:97
std::vector< std::vector< cytnx_int64 > > & qnums()
Definition Bond.hpp:154
Bond & set_type(const bondType &new_bondType)
change the tag-type of the instance Bond
Definition Bond.hpp:204
cytnx_uint64 getDegeneracy(const std::vector< cytnx_int64 > &qnum) const
return the degeneracy of specify qnum set.
Definition Bond.hpp:367
void combineBonds_(const std::vector< Bond > &bds)
combine multiple input bonds with self, inplacely
Definition Bond.hpp:340
Bond retype(const bondType &new_bondType)
create a new instance of Bond with type changed to the new tag-type:
Definition Bond.hpp:217
Bond & operator*=(const Bond &rhs)
Definition Bond.hpp:399
const std::vector< Symmetry > & syms() const
return the vector of symmetry objects by reference.
Definition Bond.hpp:185
std::vector< std::vector< cytnx_int64 > > qnums_clone() const
return copy of the current quantum number set(s)
Definition Bond.hpp:162
Bond combineBonds(const std::vector< Bond > &bds)
combine multiple input bonds with self, and return a new combined Bond instance.
Definition Bond.hpp:318
static cytnx::Bond Load(const std::string &fname)
Definition Bond.cpp:240
Bond operator*(const Bond &rhs) const
Definition Bond.hpp:395
void clear_type()
change the tag-type to the default value BD_REG
Definition Bond.hpp:239
Bond redirect() const
create a new instance of Bond with type changed in btwn BRA / KET:
Definition Bond.hpp:227
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:135
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:106
bondType type() const
return the current tag type
Definition Bond.hpp:144
Bond clone() const
return a copy of the instance Bond
Definition Bond.hpp:257
cytnx_uint64 getDegeneracy(const std::vector< cytnx_int64 > &qnum, std::vector< cytnx_uint64 > &indices) const
Definition Bond.hpp:371
std::vector< Symmetry > syms_clone() const
return copy of the vector of symmetry objects.
Definition Bond.hpp:194
Bond combineBond(const Bond &bd_in) const
combine the input bond with self, and return a new combined Bond instance.
Definition Bond.hpp:297
cytnx_uint64 dim() const
return the dimension of the bond
Definition Bond.hpp:169
std::vector< std::vector< cytnx_int64 > > getUniqueQnums()
Definition Bond.hpp:354
const std::vector< std::vector< cytnx_int64 > > & qnums() const
return the current quantum number set(s) by reference
Definition Bond.hpp:153
std::vector< Symmetry > & syms()
Definition Bond.hpp:186
void combineBond_(const Bond &bd_in)
combine the input bond with self, inplacely
Definition Bond.hpp:278
cytnx_uint32 Nsym() const
return the number of symmetries
Definition Bond.hpp:176
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:351
std::vector< std::vector< cytnx_int64 > > calc_reverse_qnums()
Definition Bond.hpp:376
bool operator!=(const Bond &rhs) const
Definition Bond.cpp:215
void Save(const std::string &fname) const
Definition Bond.cpp:220
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_IN
Definition Bond.hpp:18
@ BD_OUT
Definition Bond.hpp:19
@ BD_NONE
Definition Bond.hpp:17
@ BD_REG
Definition Bond.hpp:16
@ BD_BRA
Definition Bond.hpp:15
@ BD_KET
Definition Bond.hpp:14