4#define _USE_MATH_DEFINES
11template<
class Derived>
19 typedef typename Eigen::NumTraits<ScalarType>::Real
Real;
27 debug_constructor_printf(1(Custom Copy));
36 debug_constructor_printf(2(Custom Move));
75 __host__ __device__
int dim()
const {
76 return static_cast<Derived const*
>(
this)->dim_impl();
82 template<
typename RealType>
85 static_cast<Derived const*
>(
this)->action_impl(resBasisNum, coeff, opNum, basisNum);
88 template<
typename RealType,
class EigenDerived>
91 Eigen::DenseBase<EigenDerived>& config)
const {
92 static_cast<Derived const*
>(
this)->action_impl(resBasisNum, coeff, opNum, basisNum,
96 __host__ __device__ std::pair<int, Complex_t<Real>>
action(
int opNum,
int basisNum)
const {
100 this->
action(resBasisNum, coeff, opNum, basisNum);
101 return std::make_pair(resBasisNum, coeff);
104 __host__
void basisOp(Eigen::SparseMatrix<ScalarType>& res,
int opNum)
const {
106#pragma omp parallel for
107 for(
int basisNum = 0; basisNum < this->
baseDim(); basisNum++) {
108 auto [resBasisNum, coeff] = this->
action(opNum, basisNum);
109 res.coeffRef(resBasisNum, basisNum) = coeff;
113 __host__ Eigen::SparseMatrix<ScalarType>
basisOp(
int opNum)
const {
114 Eigen::SparseMatrix<ScalarType> res(this->
baseDim(), this->
baseDim());
115 for(
int basisNum = 0; basisNum < this->
baseDim(); basisNum++) {
117 auto [resBasisNum, coeff] = this->
action(opNum, basisNum);
118 res.insert(resBasisNum, basisNum) = coeff;
124template<
typename ScalarType>
126template<
typename ScalarType>
131template<
typename ScalarType = Complex_t<Real_t>>
145 template<
typename RealType>
147 int opNum,
int basisNum)
const {
149 resBasisNum = basisNum;
155 resBasisNum = basisNum;
156 if(opNum == 0) { coeff = 1.0 / RealType(sqrt(RealType(this->
baseSpace().
dim()))); }
157 else if(opNum == 1 && this->
baseSpace().
dim() % 2 == 0) {
158 coeff = (basisNum % 2 == 0 ? 1.0 : -1.0)
163 * (2 * (opNum / 2) * basisNum / RealType(this->
baseSpace().
dim())
164 + (opNum % 2) / 2.0))
165 / RealType(sqrt(RealType(this->
baseSpace().
dim()) / 2.0));
172 Digit1 = int(sqrt(RealType(2 * opNum) + 0.25) + 0.5);
173 Digit2 = opNum - Digit1 * (Digit1 - 1) / 2;
174 if(Digit1 == basisNum) {
175 resBasisNum = Digit2;
178 else if(Digit2 == basisNum) {
179 resBasisNum = Digit1;
186 Digit1 = int(sqrt(RealType(2 * opNum) + 0.25) + 0.5);
187 Digit2 = opNum - Digit1 * (Digit1 - 1) / 2;
188 if(Digit1 == basisNum) {
189 resBasisNum = Digit2;
192 else if(Digit2 == basisNum) {
193 resBasisNum = Digit1;
199 #ifndef __CUDA_ARCH__
200 std::cerr <<
"Error: " << __PRETTY_FUNCTION__ <<
"\n\t"
201 <<
" opNum(" << opNum <<
") must be less than "
203 std::exit(EXIT_FAILURE);
211template<
class Derived>
228 debug_constructor_printf(1(Custom Copy));
239 debug_constructor_printf(2(Custom Move));
280template<
typename ScalarType = Complex_t<Real_t>>
282template<
typename ScalarType>
288template<
typename ScalarType>
310 debug_constructor_printf(1(Custom Copy));
321 debug_constructor_printf(2(Custom Move));
369 template<
typename RealType>
371 int opNum,
int basisNum)
const {
373 resBasisNum = basisNum;
375 int locOpNum, locBasisNum;
377 for(
int pos = 0; pos != this->
sysSize(); ++pos, base *= this->
baseSpace().dimLoc()) {
378 locOpNum = this->
locState(opNum, pos);
379 locBasisNum = this->
baseSpace().locState(basisNum, pos);
380 auto [resLocBasisNum, resLocCoeff] = this->
locSpace().action(locOpNum, locBasisNum);
381 if(abs(resLocCoeff) == 0) {
383 resBasisNum = basisNum;
386 coeff *= resLocCoeff;
387 resBasisNum += (resLocBasisNum - locBasisNum) * base;
396 return this->m_bConv.
digit(state, pos);
400 Eigen::RowVectorXi res;
404 template<
class EigenDerived>
409 template<
class EigenDerived>
413 template<
class EigenDerived>
415 Eigen::DenseBase<EigenDerived>&)
const {
421template<
typename ScalarType = Complex_t<Real_t>>
423template<
typename ScalarType>
429template<
typename ScalarType>
463 debug_constructor_printf(1);
466 std::cerr <<
"ERROR: " << __PRETTY_FUNCTION__
467 <<
"\nMessage:\t m(" <<
m <<
") > "
468 <<
"baseSpace.sysSize()(" <<
baseSpace.sysSize() <<
")" << std::endl;
469 std::exit(EXIT_FAILURE);
472 for(
int j = 0; j != get_max_threads(); ++j)
m_config[j].resize(this->
sysSize());
481 debug_constructor_printf(2);
522 __host__ __device__
int m()
const {
return m_mBody; }
529 template<
typename RealType>
531 int opOrdinal,
int basisNum)
const {
535 Eigen::ArrayXi config(this->
sysSize());
536 action_impl(resBasisNum, coeff, opOrdinal, basisNum, config);
540 template<
typename RealType,
class Derived>
542 int opOrdinal,
int basisNum,
543 Eigen::DenseBase<Derived>& config)
const;
548 if(this->m_ActingSites.
locNumber(posConfNum, pos) == 0)
553 index += this->m_ActingSites.
locNumber(posConfNum, l);
556 return this->m_opConfig.
digit(opConfNum, index) + 1;
561 Eigen::ArrayXi work(this->
sysSize());
562 return this->
translate(opOrdinal, trans, work);
564 template<
class EigenDerived>
566 Eigen::DenseBase<EigenDerived>& workSpace)
const;
569 template<
class EigenDerived>
573template<
typename ScalarType>
574template<
typename RealType,
class Derived>
577 Eigen::DenseBase<Derived>& workSpace)
const {
580 if(workSpace.size() < this->sysSize())
581 debug_printf(
"%s\n\tworkSpace.size()=%d\n", __PRETTY_FUNCTION__, (
int)workSpace.size());
583 assert(workSpace.size() >= this->sysSize());
584 resBasisNum = basisNum;
589 int posConfNum = opOrdinal / m_opConfDim;
590 int opConfNum = opOrdinal % m_opConfDim;
591 this->m_ActingSites.ordinalToPart(workSpace, posConfNum);
592 int locOpNum, locBasisNum;
596 for(
int pos = 0; pos != this->sysSize(); ++pos, base *= this->baseSpace().dimLoc()) {
597 locBasisNum = this->baseSpace().locState(basisNum, pos);
598 if(workSpace[pos] == 0) {
599 this->locSpace().action(resLocBasisNum, resLocCoeff, 0, locBasisNum);
600 coeff *= resLocCoeff;
603 locOpNum = 1 + this->m_opConfig.digit(opConfNum, index++);
606 printf(
"Error: mBodyOperatorSpace::%s Out of bounds locOpNum = %d\n\n", __func__,
608 #ifndef __CUDA_ARCH__
609 std::cout <<
"locOpNum = " << locOpNum << std::endl;
610 this->m_opConfig.status();
611 std::exit(EXIT_FAILURE);
616 this->locSpace().action(resLocBasisNum, resLocCoeff, locOpNum, locBasisNum);
617 if(abs(resLocCoeff) < 1.0e-8) {
621 coeff *= resLocCoeff;
622 resBasisNum += (resLocBasisNum - locBasisNum) * base;
627template<
typename ScalarType>
628template<
class EigenDerived>
630 int opOrdinal,
int trans, Eigen::DenseBase<EigenDerived>& workSpace)
const {
631 int posConfNum = opOrdinal / m_opConfDim;
632 int opConfNum = opOrdinal % m_opConfDim;
634 workSpace.resize(this->sysSize());
636 assert(workSpace.size() >= this->sysSize());
639 if(workSpace.size() < this->sysSize())
640 debug_printf(
"%s\n\tworkSpace.size()=%d\n", __PRETTY_FUNCTION__, (
int)workSpace.size());
642 m_ActingSites.ordinalToPart(workSpace, posConfNum);
644 for(
int l = 0; l != trans; ++l) opTrans += workSpace[l];
646 posConfNum = m_ActingSites.translate(posConfNum, trans, workSpace);
647 opConfNum = this->m_opConfig.shiftDigits(opConfNum, opTrans);
648 return opConfNum + posConfNum * m_opConfDim;
651template<
typename ScalarType>
653 int basisNum)
const {
654 int posConfNum = basisNum / m_opConfDim;
655 int opConfNum = basisNum % m_opConfDim;
657 Eigen::RowVectorXi config(this->sysSize());
658 this->m_ActingSites.ordinalToPart(config, posConfNum);
661 for(
int pos = 0; pos != this->sysSize(); ++pos) {
662 if(config[pos] == 0)
continue;
663 config[pos] = 1 + this->m_opConfig.digit(opConfNum, index++);
Provides utilities for converting an integer to the corresponding expression in the positional notati...
Definition BaseNnumber.hpp:19
__host__ __device__ Integer digit(Integer const num, Integer const pos, Integer const base, Integer const length) const
Returns the (pos)-th digit of the input (num) in given base and length.
Definition BaseNnumber.hpp:113
__host__ __device__ Integer shiftDigits(Integer const num, Integer const trans, Integer const base, Integer const length) const
Shifts a number (num) to right by (trans) in terms of the positional notation with given base and len...
Definition BaseNnumber.hpp:139
__host__ __device__ Integer digitsToNumber(Input const &digits, Integer const base, Integer const length) const
Converts an array of integers to the corresponding integer in terms of the positional notation with g...
Definition BaseNnumber.hpp:166
__host__ __device__ auto printInDigits(Output &output, Integer const num, Integer const base, Integer const length) const -> typename std::enable_if< std::is_integral< Output >::value==false, BaseConverter const & >::type
Expresses an integer (num) in the positional notation with given (base) and (length)
Definition BaseNnumber.hpp:191
Definition mytypes.hpp:147
Definition HilbertSpace.hpp:47
Definition HilbertSpace.hpp:32
Lists a weak composition of an integer N up to length L with a constraint that each summand does not ...
Definition IntegerComposition.hpp:57
__host__ __device__ int locNumber(Index_ const num, Index_ const pos) const
Definition IntegerComposition.hpp:253
__host__ __device__ Index_t dim() const
Definition IntegerComposition.hpp:90
Definition OperatorSpace.hpp:213
__host__ __device__ ManyBodyOperatorSpaceBase(ManyBodyOperatorSpaceBase const &other)=default
Copy constructor.
__host__ __device__ ManyBodyOperatorSpaceBase(ManyBodyOperatorSpaceBase &&other)=default
Move constructor.
__host__ __device__ ManyBodyOperatorSpaceBase()=default
Default constructor.
__host__ __device__ ManyBodyOperatorSpaceBase & operator=(ManyBodyOperatorSpaceBase &&other)=default
Move assignment operator.
__host__ __device__ ManyBodyOperatorSpaceBase(BaseSpace const &baseSpace, int systemSize, LocalSpace const &locSpace)
Construct a ManyBodyOperatorSpaceBase object by copying.
Definition OperatorSpace.hpp:224
__host__ __device__ ManyBodyOperatorSpaceBase(BaseSpace &&baseSpace, int systemSize, LocalSpace &&locSpace)
Construct a ManyBodyOperatorSpaceBase object by moving.
Definition OperatorSpace.hpp:235
__host__ __device__ ManyBodyOperatorSpaceBase & operator=(ManyBodyOperatorSpaceBase const &other)=default
Copy assignment operator.
typename HilbertSpaceTraits< Derived >::LocalSpace LocalSpace
Definition OperatorSpace.hpp:217
typename HilbertSpaceTraits< Derived >::BaseSpace BaseSpace
Definition OperatorSpace.hpp:216
__host__ __device__ ~ManyBodyOperatorSpaceBase()=default
Destructor.
Definition OperatorSpace.hpp:290
__host__ __device__ ManyBodyOperatorSpace()=default
Default constructor.
__host__ __device__ ManyBodyOperatorSpace(BaseSpace const &baseSpace)
Construct a ManyBodyOperatorSpace object by copying a BaseSpace object.
Definition OperatorSpace.hpp:307
__host__ __device__ void action_impl(int &resBasisNum, Complex_t< RealType > &coeff, int opNum, int basisNum) const
Definition OperatorSpace.hpp:370
__host__ __device__ int translate_impl(int state, int trans, Eigen::DenseBase< EigenDerived > &) const
Definition OperatorSpace.hpp:414
__host__ __device__ int locState_impl(int state, int pos) const
Definition OperatorSpace.hpp:395
typename HilbertSpaceTraits< ManyBodyOperatorSpace< ScalarType > >::BaseSpace BaseSpace
Definition OperatorSpace.hpp:298
__host__ __device__ int dim_impl() const
Definition OperatorSpace.hpp:362
__host__ __device__ ManyBodyOperatorSpace(ManyBodyOperatorSpace const &other)=default
Copy constructor.
__host__ __device__ ManyBodyOperatorSpace & operator=(ManyBodyOperatorSpace &&other)=default
Move assignment operator.
__host__ __device__ ManyBodyOperatorSpace & operator=(ManyBodyOperatorSpace const &other)=default
Copy assignment operator.
__host__ __device__ ManyBodyOperatorSpace(ManyBodyOperatorSpace &&other)=default
Move constructor.
__host__ __device__ ~ManyBodyOperatorSpace()=default
Destructor.
ScalarType Scalar
Definition OperatorSpace.hpp:295
__host__ __device__ int configToOrdinal_impl(Eigen::DenseBase< EigenDerived > &config) const
Definition OperatorSpace.hpp:405
BaseConverter< int > m_bConv
Definition OperatorSpace.hpp:292
__host__ __device__ ManyBodyOperatorSpace(BaseSpace &&baseSpace)
Construct a ManyBodyOperatorSpace object by moving a BaseSpace object.
Definition OperatorSpace.hpp:317
__host__ __device__ int translate_impl(int state, int trans) const
Definition OperatorSpace.hpp:410
typename HilbertSpaceTraits< ManyBodyOperatorSpace< ScalarType > >::LocalSpace LocalSpace
Definition OperatorSpace.hpp:300
__host__ __device__ Eigen::RowVectorXi ordinalToConfig_impl(int basisNum) const
Definition OperatorSpace.hpp:399
ManyBodySpinSpace defined by , where.
Definition HilbertSpace.hpp:130
__host__ __device__ LocSpace_t const & locSpace() const
Definition HilbertSpace.hpp:264
int m_systemSize
Definition HilbertSpace.hpp:141
__host__ __device__ int translate(int state, int trans) const
Translate the input state to the left by one.
Definition HilbertSpace.hpp:300
__host__ __device__ int dimLoc() const
Definition HilbertSpace.hpp:266
__host__ __device__ int locState(int state, int pos) const
Definition HilbertSpace.hpp:267
__host__ __device__ int sysSize() const
Definition HilbertSpace.hpp:265
Definition HilbertSpace.hpp:423
Definition OperatorSpace.hpp:12
__host__ __device__ void action(int &resBasisNum, Complex_t< RealType > &coeff, int opNum, int basisNum, Eigen::DenseBase< EigenDerived > &config) const
Definition OperatorSpace.hpp:89
__host__ __device__ OperatorSpaceBase & operator=(OperatorSpaceBase &&other)=default
Move assignment operator.
__host__ __device__ OperatorSpaceBase(BaseSpace &&baseSpace)
Construct a OperatorSpaceBase object by moving a BaseSpace object.
Definition OperatorSpace.hpp:34
Eigen::NumTraits< ScalarType >::Real Real
Definition OperatorSpace.hpp:19
__host__ __device__ int dim() const
Definition OperatorSpace.hpp:75
__host__ __device__ std::pair< int, Complex_t< Real > > action(int opNum, int basisNum) const
Definition OperatorSpace.hpp:96
__host__ __device__ OperatorSpaceBase()=default
Default constructor.
__host__ __device__ void action(int &resBasisNum, Complex_t< RealType > &coeff, int opNum, int basisNum) const
Definition OperatorSpace.hpp:83
__host__ __device__ OperatorSpaceBase & operator=(OperatorSpaceBase const &other)=default
Copy assignment operator.
__host__ __device__ OperatorSpaceBase(BaseSpace const &baseSpace)
Construct a OperatorSpaceBase object by copying a BaseSpace object.
Definition OperatorSpace.hpp:26
__host__ __device__ int baseDim() const
Definition OperatorSpace.hpp:80
typename HilbertSpaceTraits< Derived >::BaseSpace BaseSpace
Definition OperatorSpace.hpp:14
BaseSpace m_baseSpace
Definition OperatorSpace.hpp:16
__host__ Eigen::SparseMatrix< ScalarType > basisOp(int opNum) const
Definition OperatorSpace.hpp:113
__host__ void basisOp(Eigen::SparseMatrix< ScalarType > &res, int opNum) const
Definition OperatorSpace.hpp:104
__host__ __device__ ~OperatorSpaceBase()=default
Destructor.
__host__ __device__ OperatorSpaceBase(OperatorSpaceBase const &other)=default
Copy constructor.
__host__ __device__ BaseSpace const & baseSpace() const
Definition OperatorSpace.hpp:79
__host__ __device__ OperatorSpaceBase(OperatorSpaceBase &&other)=default
Move constructor.
typename HilbertSpaceTraits< Derived >::Scalar ScalarType
Definition OperatorSpace.hpp:15
Definition OperatorSpace.hpp:132
typename HilbertSpaceTraits< OperatorSpace >::BaseSpace BaseSpace
Definition OperatorSpace.hpp:135
ScalarType Scalar
Definition OperatorSpace.hpp:136
__host__ __device__ int dim_impl() const
Definition OperatorSpace.hpp:140
__host__ __device__ void action_impl(int &resBasisNum, Complex_t< RealType > &coeff, int opNum, int basisNum) const
Definition OperatorSpace.hpp:146
Definition OperatorSpace.hpp:430
__host__ __device__ int locState_impl(int opOrdinal, int pos) const
Definition OperatorSpace.hpp:546
__host__ __device__ int dim_impl() const
Definition OperatorSpace.hpp:526
__host__ __device__ mBodyOperatorSpace(mBodyOperatorSpace const &other)=default
Copy constructor.
__host__ __device__ mBodyOperatorSpace & operator=(mBodyOperatorSpace &&other)=default
Move assignment operator.
int m_opConfDim
Definition OperatorSpace.hpp:438
BaseConverter< int > m_opConfig
Definition OperatorSpace.hpp:440
__host__ __device__ mBodyOperatorSpace(int m, BaseSpace const &baseSpace)
Construct an mBodyOperatorSpace object by copying a BaseSpace object.
Definition OperatorSpace.hpp:457
__host__ __device__ mBodyOperatorSpace(int m, int sysSize, int dimLoc)
Construct an mBodyOperatorSpace object by copying a BaseSpace object.
Definition OperatorSpace.hpp:479
__host__ __device__ int m() const
Definition OperatorSpace.hpp:522
__host__ __device__ int translate_impl(int opOrdinal, int trans) const
Definition OperatorSpace.hpp:560
__host__ __device__ void action_impl(int &resBasisNum, Complex_t< RealType > &coeff, int opOrdinal, int basisNum) const
Definition OperatorSpace.hpp:530
__host__ __device__ mBodyOperatorSpace(mBodyOperatorSpace &&other)=default
Move constructor.
__host__ __device__ mBodyOperatorSpace & operator=(mBodyOperatorSpace const &other)=default
Copy assignment operator.
Array_t< Array_t< int > > m_config
Definition OperatorSpace.hpp:442
__host__ __device__ int configToOrdinal_impl(Eigen::DenseBase< EigenDerived > &config) const
ScalarType Scalar
Definition OperatorSpace.hpp:446
__host__ __device__ void action_impl(int &resBasisNum, Complex_t< RealType > &coeff, int opOrdinal, int basisNum, Eigen::DenseBase< Derived > &config) const
Definition OperatorSpace.hpp:575
Eigen::ArrayX< T > Array_t
Definition OperatorSpace.hpp:435
__host__ __device__ ~mBodyOperatorSpace()=default
Destructor.
typename HilbertSpaceTraits< mBodyOperatorSpace< ScalarType > >::LocalSpace LocalSpace
Definition OperatorSpace.hpp:450
typename HilbertSpaceTraits< mBodyOperatorSpace< ScalarType > >::BaseSpace BaseSpace
Definition OperatorSpace.hpp:448
__host__ __device__ int translate_impl(int opOrdinal, int trans, Eigen::DenseBase< EigenDerived > &workSpace) const
Definition OperatorSpace.hpp:629
IntegerComposition m_ActingSites
Definition OperatorSpace.hpp:439
__host__ __device__ mBodyOperatorSpace()=default
Default constructor.
__host__ __device__ Eigen::RowVectorXi ordinalToConfig_impl(int basisNum) const
Definition OperatorSpace.hpp:652
Eigen::VectorX< T > Vector_t
Definition OperatorSpace.hpp:433
int m_mBody
Definition OperatorSpace.hpp:437
ScalarType Scalar
Definition OperatorSpace.hpp:286
ScalarType Scalar
Definition OperatorSpace.hpp:129
ScalarType Scalar
Definition OperatorSpace.hpp:427
Definition HilbertSpace.hpp:23