DMRGKron.hpp
1 #ifndef __DMRG_KRON_HPP
2 #define __DMRG_KRON_HPP
3 
11 #include <petscsys.h>
12 #include <slepceps.h>
13 
14 #include "DMRGBlock.hpp"
15 #include "Hamiltonians.hpp"
16 
22 typedef std::tuple<PetscReal, PetscInt, PetscInt, PetscInt> KronBlock_t;
23 
24 PETSC_EXTERN PetscErrorCode MatMult_KronSumShell(Mat A, Vec x, Vec y);
25 
28 struct KronSumTerm {
29  PetscScalar a;
30  Op_t OpTypeA;
31  Mat A;
32  Op_t OpTypeB;
33  Mat B;
34 };
35 
37 struct KronSumCtx {
38  PetscInt rstart=0;
39  PetscInt rend=0;
40  PetscInt lrows=0;
41  PetscInt cstart=0;
42  PetscInt cend=0;
43  PetscInt lcols=0;
44  PetscInt Nrows=0;
45  PetscInt Ncols=0;
48  PetscInt NReqRowsL, NReqRowsR;
49 
51  std::vector< PetscInt > ReqRowsL, ReqRowsR;
52 
54  std::unordered_map< PetscInt, PetscInt > MapRowsL, MapRowsR;
55 
57  std::vector< KronSumTerm > Terms;
58 
60  std::vector< Mat* > LocalSubMats;
61 
63  PetscInt *Dnnz;
64 
66  PetscInt *Onnz;
67 
69  PetscInt MinIdx=0;
70 
72  PetscInt MaxIdx=0;
73 
75  std::vector< PetscInt > Maxnnz;
76 
77  PetscInt Nfiltered=0;
78 
79  PetscInt Nnz=0;
80 
81  PetscInt Nelts=0;
82 };
83 
86  PetscInt nz_L, nz_R, bks_L, col_NStatesR, fws_O;
87  PetscInt *idx_L, *idx_R;
88  PetscScalar *v_L, *v_R;
89 };
90 
93 
97 
100  PetscInt Nterms;
101  PetscInt Nrowterms;
102 
103  PetscInt *Rows_L;
104  PetscInt *Rows_R;
105  PetscScalar *term_a;
106 
107  PetscScalar one;
108 
109  /* Mat-Vec multiplication */
110  VecScatter vsctx;
111  Vec x_seq;
112 };
113 
114 PetscErrorCode MatDestroy_KronSumShell(Mat *p_mat);
115 
118 {
119 
120 friend class KronBlocksIterator;
121 
122 public:
123 
125  Block::SpinBase& LeftBlock,
126  Block::SpinBase& RightBlock,
127  const std::vector<PetscReal>& QNSectors,
128  FILE *fp_prealloc,
129  const PetscInt& GlobIdx
130  ):
131  GlobIdx(GlobIdx),
132  LeftBlock(LeftBlock),
133  RightBlock(RightBlock),
134  fp_prealloc(fp_prealloc)
135  {
136  /* Require blocks to be initialized */
137  if(!LeftBlock.Initialized()) throw std::runtime_error("Left input block not initialized.");
138  if(!RightBlock.Initialized()) throw std::runtime_error("Right input block not initialized.");
139  /* Fill in mpi information */
140  mpi_comm = LeftBlock.MPIComm();
141  if(mpi_comm != RightBlock.MPIComm())
142  throw std::runtime_error("Left and right blocks must have the same communicator.");
143  if(MPI_Comm_rank(mpi_comm, &mpi_rank)) throw std::runtime_error("MPI Error.");
144  if(MPI_Comm_size(mpi_comm, &mpi_size)) throw std::runtime_error("MPI Error.");
145 
147  if(QNSectors.size() == 0)
148  {
149  for (size_t IL = 0; IL < LeftBlock.Magnetization.List().size(); ++IL){
150  for (size_t IR = 0; IR < RightBlock.Magnetization.List().size(); ++IR){
151  KronBlocks.push_back(std::make_tuple(
152  LeftBlock.Magnetization.List()[IL] + RightBlock.Magnetization.List()[IR], IL, IR,
153  LeftBlock.Magnetization.Sizes()[IL] * RightBlock.Magnetization.Sizes()[IR]));
154  }
155  }
156  /* Sort by descending quantum numbers */
157  std::stable_sort(KronBlocks.begin(), KronBlocks.end(), DescendingQN);
158  }
160  else if (QNSectors.size() == 1)
161  {
162  for (size_t IL = 0; IL < LeftBlock.Magnetization.List().size(); ++IL){
163  for (size_t IR = 0; IR < RightBlock.Magnetization.List().size(); ++IR){
164  PetscReal QN = LeftBlock.Magnetization.List()[IL] + RightBlock.Magnetization.List()[IR];
165  if(QN == QNSectors[0])
166  KronBlocks.push_back(std::make_tuple(
167  QN, IL, IR,
168  LeftBlock.Magnetization.Sizes()[IL] * RightBlock.Magnetization.Sizes()[IR]));
169  }
170  }
171  }
173  else
174  {
175  /* Convert QNSectors into a set */
176  std::set< PetscReal > QNSectorsSet(QNSectors.begin(), QNSectors.end());
177  for (size_t IL = 0; IL < LeftBlock.Magnetization.List().size(); ++IL){
178  for (size_t IR = 0; IR < RightBlock.Magnetization.List().size(); ++IR){
179  PetscReal QN = LeftBlock.Magnetization.List()[IL] + RightBlock.Magnetization.List()[IR];
180  if(QNSectorsSet.find(QN) != QNSectorsSet.end())
181  KronBlocks.push_back(std::make_tuple(
182  QN, IL, IR,
183  LeftBlock.Magnetization.Sizes()[IL] * RightBlock.Magnetization.Sizes()[IR]));
184  }
185  }
186  }
187 
188  /* Fill-in size and offset data from the sorted blocks */
189  num_blocks = KronBlocks.size();
190  kb_list.reserve(num_blocks);
191  kb_size.reserve(num_blocks);
192  kb_offset.reserve(num_blocks+1);
193 
194  /* Unload the data into separate vectors */
195  for(KronBlock_t kb: KronBlocks) kb_list.push_back(std::get<0>(kb));
196  for(KronBlock_t kb: KronBlocks) kb_size.push_back(std::get<3>(kb));
197 
198  PetscInt idx = 0;
199  for(KronBlock_t kb: KronBlocks)
200  kb_map[std::make_tuple( std::get<1>(kb), std::get<2>(kb) )] = idx++;
201 
202  PetscInt sum = 0;
203  for(KronBlock_t kb: KronBlocks)
204  {
205  kb_offset.push_back(sum);
206  sum += std::get<3>(kb);
207  }
208  kb_offset.push_back(sum);
209  num_states = sum;
210 
211  do_saveprealloc = PetscBool(fp_prealloc!=NULL);
212  MPIU_Allreduce(MPI_IN_PLACE, &do_saveprealloc, 1, MPI_INT, MPI_SUM, PETSC_COMM_WORLD);
213  };
214 
216  PetscInt size() const { return PetscInt(KronBlocks.size()); }
217 
219  const std::vector<KronBlock_t>& data() const { return KronBlocks; }
220 
222  KronBlock_t data(size_t idx) const { return KronBlocks[idx]; }
223 
225  KronBlock_t operator[](size_t idx) const { return KronBlocks[idx]; }
226 
228  std::vector<PetscReal> List() const { return kb_list; }
229 
231  std::vector<PetscInt> Offsets() const { return kb_offset; }
232 
234  PetscInt Offsets(const PetscInt& idx ) const {
235  assert(idx >= 0 && idx < num_blocks + 1);
236  return kb_offset[idx];
237  }
238 
240  PetscReal QN(const PetscInt& idx) const {
241  return std::get<0>(KronBlocks[idx]);
242  }
243 
245  PetscInt LeftIdx(const PetscInt& idx) const {
246  return std::get<1>(KronBlocks[idx]);
247  }
248 
250  PetscInt RightIdx(const PetscInt& idx) const {
251  return std::get<2>(KronBlocks[idx]);
252  }
253 
255  PetscInt Sizes(const PetscInt& idx) const {
256  return std::get<3>(KronBlocks[idx]);
257  }
258 
260  const Block::SpinBase& LeftBlockRef() const { return LeftBlock; }
261 
263  const Block::SpinBase& RightBlockRef() const { return RightBlock; }
264 
266  Block::SpinBase& LeftBlockRefMod(){ return LeftBlock; }
267 
269  Block::SpinBase& RightBlockRefMod(){ return RightBlock; }
270 
272  PetscInt Offsets(const PetscInt& lidx, const PetscInt& ridx) const {
273  PetscInt idx = Map(lidx, ridx);
274  if(idx >= 0) return kb_offset[idx];
275  else return -1;
276  }
277 
279  std::vector<PetscInt> Sizes() const{ return kb_size; }
280 
283  PetscInt Map(const PetscInt& lidx, const PetscInt& ridx) const
284  {
285  auto tup = std::make_tuple(lidx,ridx);
286  auto kb_find = kb_map.find(tup);
287  if(kb_find != kb_map.end())
288  {
289  return kb_find->second;
290  } else
291  {
292  return -1;
293  }
294  }
295 
297  PetscInt NumStates() const { return num_states; }
298 
300  PetscErrorCode KronSumConstruct(
301  const std::vector< Hamiltonians::Term >& Terms,
302  Mat& MatOut
303  );
304 
309  PetscErrorCode KronConstruct(
310  const Mat& Mat_L,
311  const Op_t& OpType_L,
312  const Mat& Mat_R,
313  const Op_t& OpType_R,
314  Mat& MatOut
315  );
316 
318  PetscErrorCode KronSumSetShellMatrix(const PetscBool& do_shell_in)
319  {
320  do_shell = do_shell_in;
321  return(0);
322  }
323 
324  PetscErrorCode KronSumSetRedistribute(
325  const PetscBool& do_redistribute_in = PETSC_TRUE
326  )
327  {
328  do_redistribute = do_redistribute_in;
329  return(0);
330  }
331 
332  PetscErrorCode KronSumSetToleranceFromOptions()
333  {
334  PetscErrorCode ierr;
335  ierr = PetscOptionsGetReal(NULL,NULL,"-ks_tol",&ks_tol,NULL); CHKERRQ(ierr);
336  return(0);
337  }
338 
339 private:
340 
341  MPI_Comm mpi_comm = PETSC_COMM_SELF;
342  PetscMPIInt mpi_rank, mpi_size;
343 
344  const PetscInt GlobIdx;
345 
347  std::vector<KronBlock_t> KronBlocks;
348 
350  std::vector<PetscReal> kb_list;
351 
353  std::vector<PetscInt> kb_size;
354 
356  std::vector<PetscInt> kb_offset;
357 
359  std::map< std::tuple<PetscInt,PetscInt>, PetscInt > kb_map;
360 
362  PetscInt num_blocks = 0;
363 
365  PetscInt num_states = 0;
366 
369 
372 
374  FILE *fp_prealloc;
375 
377  PetscBool do_saveprealloc = PETSC_FALSE;
378 
380  PetscBool do_redistribute = PETSC_FALSE;
381 
383  PetscBool do_shell = PETSC_FALSE;
384 
386  PetscBool called_KronSumShellSplitOwnership = PETSC_FALSE;
387 
389  PetscInt prev_lrows = 0;
390 
392  PetscInt prev_rstart = 0;
393 
395  #if defined(PETSC_USE_REAL_DOUBLE)
396  PetscReal ks_tol = 1.0e-16;
397  #else
398  #error Only double precision real numbers supported.
399  #endif
400 
402  static bool DescendingQN(const KronBlock_t& a, const KronBlock_t& b)
403  {
404  return (std::get<0>(a)) > (std::get<0>(b));
405  }
406 
408  PetscErrorCode MatKronEyeAdd(
409  const std::vector< Mat >& Matrices,
410  const Side_t& SideType,
411  Mat& MatOut
412  );
413 
417  PetscErrorCode VerifySzAssumption(
418  const std::vector< Mat >& Matrices,
419  const Side_t& SideType
420  );
421 
422  PetscErrorCode KronGetSubmatrices(
423  const Mat& Mat_L,
424  const Op_t& OpType_L,
425  const Mat& Mat_R,
426  const Op_t& OpType_R,
427  KronSumCtx& ctx
428  );
429 
430  PetscErrorCode KronSumConstructExplicit(
431  const std::vector< Hamiltonians::Term >& TermsLR,
432  Mat& MatOut
433  );
434 
435  PetscErrorCode KronSumConstructShell(
436  const std::vector< Hamiltonians::Term >& TermsLR,
437  Mat& MatOut
438  );
439 
440  PetscErrorCode KronSumSetUpShellTerms(
441  KronSumShellCtx *shellctx
442  );
443 
444  PetscErrorCode KronSumGetSubmatrices(
445  const Mat& OpProdSumLL,
446  const Mat& OpProdSumRR,
447  const std::vector< Hamiltonians::Term >& TermsLR,
448  KronSumCtx& SubMat
449  );
450 
451  PetscErrorCode KronSumCalcPreallocation(
452  KronSumCtx& ctx
453  );
454 
455  PetscErrorCode KronSumShellSplitOwnership(
456  const Mat& OpProdSumLL,
457  const Mat& OpProdSumRR,
458  const std::vector< Hamiltonians::Term >& TermsLR,
459  const PetscInt Nrows,
460  PetscInt& lrows,
461  PetscInt& rstart
462  );
463 
464  PetscErrorCode KronSumRedistribute(
465  KronSumCtx& ctx,
466  PetscBool& flg
467  );
468 
469  PetscErrorCode KronSumPreallocate(
470  KronSumCtx& ctx,
471  Mat& MatOut
472  );
473 
474  PetscErrorCode KronSumFillMatrix(
475  KronSumCtx& ctx,
476  Mat& MatOut
477  );
478 
479  PetscErrorCode SavePreallocData(const KronSumCtx& ctx);
480 };
481 
482 
484 PetscErrorCode KronEye_Explicit(
485  Block::SpinBase& LeftBlock,
486  Block::SpinBase& RightBlock,
487  const std::vector< Hamiltonians::Term >& Terms,
488  Block::SpinBase& BlockOut
489  );
490 
502 {
503 public:
504 
505  typedef KronBlocksIterator Self_t;
506 
509  const KronBlocks_t& KronBlocks,
510  const PetscInt& GlobIdxStart,
511  const PetscInt& GlobIdxEnd
512  ):
513  KronBlocks(KronBlocks),
514  istart_(GlobIdxStart),
515  iend_(GlobIdxEnd),
516  idx_(istart_)
517  {
518  if(istart_==iend_) {}
519  else
520  {
521  kb_size.reserve(KronBlocks.size());
522  kb_offset.reserve(KronBlocks.size()+1);
523 
524  for(KronBlock_t kb: KronBlocks.data()) kb_size.push_back(std::get<3>(kb));
525 
526  PetscInt sum = 0;
527  for(KronBlock_t kb: KronBlocks.data())
528  {
529  kb_offset.push_back(sum);
530  sum += std::get<3>(kb);
531  }
532  kb_offset.push_back(sum);
533  num_states = sum;
534  assert(istart_ < sum);
535 
536  while(idx_ >= kb_offset[blockidx_+1]) ++blockidx_;
537  }
538  }
539 
541  PetscInt IdxStart() const {return istart_;}
542 
544  PetscInt IdxEnd() const {return iend_;}
545 
547  PetscInt Idx() const {return idx_;}
548 
550  PetscInt BlockIdx() const {return blockidx_;}
551 
553  PetscInt LocIdx() const {return idx_ - kb_offset[blockidx_];}
554 
556  PetscInt BlockStartIdx(
557  const PetscInt& BlockShift
558  ) const
559  {
560  PetscInt BlockIdx_out = blockidx_ + BlockShift;
561  if(BlockIdx_out < 0 || BlockIdx_out >= num_states){
562  return -1;
563  }
564  return kb_offset[BlockIdx_out];
565  }
566 
568  PetscInt BlockSize(
569  const PetscInt& BlockShift
570  ) const
571  {
572  PetscInt BlockIdx_out = blockidx_ + BlockShift;
573  if(BlockIdx_out < 0 || BlockIdx_out >= num_states){
574  return -1;
575  }
576  return kb_size[BlockIdx_out];
577  }
578 
579 
581  bool Loop() const {return idx_ < iend_;}
582 
584  PetscInt Steps() const {return idx_-istart_;}
585 
587  Self_t operator++()
588  {
589  ++idx_;
590  if(idx_ >= kb_offset[blockidx_+1]){
591  ++blockidx_;
592  updated_block = PETSC_TRUE;
593  } else {
594  updated_block = PETSC_FALSE;
595  }
596  return *this;
597  }
598 
600  PetscInt BlockIdxLeft() const {return std::get<1>(KronBlocks.data()[blockidx_]);}
601 
603  PetscInt LocIdxLeft() const { return LocIdx() / NumStatesRight(); }
604 
606  PetscInt NumStatesRight() const { return KronBlocks.RightBlock.Magnetization.Sizes()[BlockIdxRight()]; }
607 
609  PetscInt BlockIdxRight() const {return std::get<2>(KronBlocks.data()[blockidx_]);}
610 
612  PetscInt LocIdxRight() const { return LocIdx() % NumStatesRight(); }
613 
614  PetscInt GlobalIdxLeft() const {
615  return KronBlocks.LeftBlock.Magnetization.BlockIdxToGlobalIdx(BlockIdxLeft(), LocIdxLeft());
616  }
617 
618  PetscInt GlobalIdxRight() const {
619  return KronBlocks.RightBlock.Magnetization.BlockIdxToGlobalIdx(BlockIdxRight(), LocIdxRight());
620  }
621 
623  PetscBool UpdatedBlock() const {return updated_block; }
624 
625 private:
626 
629 
631  PetscInt istart_ = 0;
632 
634  PetscInt iend_ = 0;
635 
637  PetscInt idx_ = 0;
638 
640  PetscInt blockidx_ = -1;
641 
643  PetscInt locidx_ = 0;
644 
646  std::vector<PetscInt> kb_size;
647 
649  std::vector<PetscInt> kb_offset;
650 
652  PetscInt num_states = 0;
653 
655  PetscBool updated_block = PETSC_TRUE;
656 };
657 
658 
663 #endif // __DMRG_KRON_HPP
std::vector< PetscInt > Sizes() const
Returns the number of basis states in each quantum number block.
Definition: DMRGKron.hpp:279
PetscInt Steps() const
Gets the number of steps incremented from the starting index.
Definition: DMRGKron.hpp:584
Block::SpinBase & LeftBlock
Reference to the left block object.
Definition: DMRGKron.hpp:368
PetscInt num_states
Total number of states.
Definition: DMRGKron.hpp:652
Block::SpinBase & RightBlock
Reference to the right block object.
Definition: DMRGKron.hpp:371
Block::SpinBase & RightBlockRefMod()
Returns a non-const reference to the right block object.
Definition: DMRGKron.hpp:269
PetscInt BlockSize(const PetscInt &BlockShift) const
Gets the size of the block with a shift.
Definition: DMRGKron.hpp:568
PetscInt Offsets(const PetscInt &lidx, const PetscInt &ridx) const
Returns the offsets for the KronBlock corresponding to a pair of left and right block indices...
Definition: DMRGKron.hpp:272
std::map< std::tuple< PetscInt, PetscInt >, PetscInt > kb_map
Kronecker product mapping from (L,R) block to the corresponding index.
Definition: DMRGKron.hpp:359
Base class for the implementation of a block of spin sites.
Definition: DMRGBlock.hpp:79
Block::SpinBase & LeftBlockRefMod()
Returns a non-const reference to the left block object.
Definition: DMRGKron.hpp:266
Calculates the sum of the Kronecker product of operators on two blocks following the terms of a Hamil...
Definition: DMRGKron.hpp:501
PetscInt size() const
Returns the total number blocks.
Definition: DMRGKron.hpp:216
PetscInt Map(const PetscInt &lidx, const PetscInt &ridx) const
Returns the position index of the KronBlock corresponding to a pair of left and right block indices; ...
Definition: DMRGKron.hpp:283
A single term of the KronSum.
Definition: DMRGKron.hpp:28
PetscInt Sizes(const PetscInt &idx) const
Returns the number of basis states for a given KronBlock index.
Definition: DMRGKron.hpp:255
Context structure defining a single row of KronSumShell.
Definition: DMRGKron.hpp:85
std::vector< KronBlock_t > KronBlocks
Storage for kronblocks.
Definition: DMRGKron.hpp:347
std::vector< KronSumTerm > Terms
Lists down all the terms of the KronSum with Mat entries filled with local submatrices.
Definition: DMRGKron.hpp:57
PetscInt RightIdx(const PetscInt &idx) const
Returns the left quantum number index (KronBlocks 1st endtry) for a given KronBlock index...
Definition: DMRGKron.hpp:250
std::vector< PetscReal > List() const
Returns the list of quantum numbers.
Definition: DMRGKron.hpp:228
PetscErrorCode KronEye_Explicit(Block::SpinBase &LeftBlock, Block::SpinBase &RightBlock, const std::vector< Hamiltonians::Term > &Terms, Block::SpinBase &BlockOut)
Calculates a new block combining two spin-1/2 blocks.
Definition: DMRGKron.cpp:459
FILE * fp_prealloc
File to store preallocation data for each processor.
Definition: DMRGKron.hpp:374
Op_t
Identifies the three possible spin operators and also represents the shift associated to its action o...
Definition: DMRGBlock.hpp:21
PetscBool UpdatedBlock() const
Gets the update state of the block index from the previous increment.
Definition: DMRGKron.hpp:623
PetscInt * Onnz
Preallocation data of the output matrix for local off-diagonal diagonal rows.
Definition: DMRGKron.hpp:66
std::unordered_map< PetscInt, PetscInt > MapRowsL
Maps the global indices of the rows of L and R to their local indices in the corresponding submatrice...
Definition: DMRGKron.hpp:54
PetscInt IdxStart() const
Gets the first quantum number block index.
Definition: DMRGKron.hpp:541
PetscInt Offsets(const PetscInt &idx) const
Returns the offsets for a given index.
Definition: DMRGKron.hpp:234
std::vector< PetscReal > List() const
Returns the list of quantum numbers.
PetscInt LocIdx() const
Gets the current local index in the quantum number block.
Definition: DMRGKron.hpp:553
std::vector< PetscInt > kb_size
Number of states in each quantum number block.
Definition: DMRGKron.hpp:646
std::vector< PetscInt > Maxnnz
Predicted maximum number of elements on each local row.
Definition: DMRGKron.hpp:75
std::vector< Mat * > LocalSubMats
List of unique submatrices to be destroyed later.
Definition: DMRGKron.hpp:60
PetscInt BlockIdxLeft() const
Gets the block index for the left side.
Definition: DMRGKron.hpp:600
KronBlocksIterator(const KronBlocks_t &KronBlocks, const PetscInt &GlobIdxStart, const PetscInt &GlobIdxEnd)
Initialize an iterator through a range of indices.
Definition: DMRGKron.hpp:508
PetscInt IdxEnd() const
Gets the first quantum number block index.
Definition: DMRGKron.hpp:544
KronBlocks_t(Block::SpinBase &LeftBlock, Block::SpinBase &RightBlock, const std::vector< PetscReal > &QNSectors, FILE *fp_prealloc, const PetscInt &GlobIdx)
Definition: DMRGKron.hpp:124
std::vector< PetscInt > ReqRowsL
List of required rows of the left and right blocks.
Definition: DMRGKron.hpp:51
PetscReal QN(const PetscInt &idx) const
Returns the left quantum number index (KronBlocks 1st endtry) for a given KronBlock index...
Definition: DMRGKron.hpp:240
std::vector< PetscInt > Sizes() const
Returns the number of basis states in each quantum number block.
PetscInt * Dnnz
Preallocation data of the output matrix for local diagonal rows.
Definition: DMRGKron.hpp:63
const Block::SpinBase & LeftBlockRef() const
Returns a const reference to the left block object.
Definition: DMRGKron.hpp:260
PetscInt BlockStartIdx(const PetscInt &BlockShift) const
Gets the column index of the starting block with a shift.
Definition: DMRGKron.hpp:556
std::vector< PetscInt > kb_offset
Offset for each quantum number block.
Definition: DMRGKron.hpp:649
KronSumTermRow * kstr
Contains the KronSumTermRow&#39;s needed for calculating the terms of the full matrix.
Definition: DMRGKron.hpp:99
PetscBool Initialized() const
Indicates whether block has been initialized before using it.
Definition: DMRGBlock.hpp:335
std::vector< PetscInt > kb_size
(Redundant) storage for sizes of each quantum number block
Definition: DMRGKron.hpp:353
const std::vector< KronBlock_t > & data() const
Returns a const reference to the KronBlocks object.
Definition: DMRGKron.hpp:219
std::vector< PetscReal > kb_list
(Redundant) storage for quantum numbers
Definition: DMRGKron.hpp:350
PetscInt NReqRowsL
Number of required rows of the left and right blocks.
Definition: DMRGKron.hpp:48
PetscErrorCode KronSumSetShellMatrix(const PetscBool &do_shell_in)
Decide whether to create an implicit MATSHELL matrix.
Definition: DMRGKron.hpp:318
std::vector< PetscInt > Offsets() const
Returns the offsets for each quantum number block.
Definition: DMRGKron.hpp:231
std::tuple< PetscReal, PetscInt, PetscInt, PetscInt > KronBlock_t
Storage for information on resulting blocks of quantum numbers stored as a tuple for quick sorting...
Definition: DMRGKron.hpp:22
PetscInt LocIdxRight() const
Gets the local index for the right side.
Definition: DMRGKron.hpp:612
KronSumCtx * p_ctx
Contains the usual ctx object for explicit matrices.
Definition: DMRGKron.hpp:96
std::vector< PetscInt > kb_offset
Storage for offsets or starting elements of each block.
Definition: DMRGKron.hpp:356
const Block::SpinBase & RightBlockRef() const
Returns a const reference to the right block object.
Definition: DMRGKron.hpp:263
PetscInt BlockIdx() const
Gets the current quantum number block index.
Definition: DMRGKron.hpp:550
PetscInt LeftIdx(const PetscInt &idx) const
Returns the left quantum number index (KronBlocks 1st endtry) for a given KronBlock index...
Definition: DMRGKron.hpp:245
KronBlock_t data(size_t idx) const
Returns the KronBlock for specified index.
Definition: DMRGKron.hpp:222
Context for the shell matrix object.
Definition: DMRGKron.hpp:92
A container of ordered KronBlock_t objects representing a Kronecker product structure.
Definition: DMRGKron.hpp:117
QuantumNumbers Magnetization
Stores the information on the magnetization Sectors.
Definition: DMRGBlock.hpp:326
Self_t operator++()
Overloading the ++ increment.
Definition: DMRGKron.hpp:587
KronBlock_t operator[](size_t idx) const
Returns the KronBlock for specified index.
Definition: DMRGKron.hpp:225
const KronBlocks_t & KronBlocks
Reference to the KronBlocks object on which this iterator is based on.
Definition: DMRGKron.hpp:628
MPI_Comm MPIComm() const
Gets the communicator associated to the block.
Definition: DMRGBlock.hpp:341
PetscInt LocIdxLeft() const
Gets the local index for the left side.
Definition: DMRGKron.hpp:603
PetscInt NumStates() const
Returns the total number of states.
Definition: DMRGKron.hpp:297
PetscInt Idx() const
Gets the current state index.
Definition: DMRGKron.hpp:547
bool Loop() const
Determines whether the end of the range has not yet been reached.
Definition: DMRGKron.hpp:581
static bool DescendingQN(const KronBlock_t &a, const KronBlock_t &b)
Tolerance.
Definition: DMRGKron.hpp:402
PetscInt BlockIdxRight() const
Gets the block index for the right side.
Definition: DMRGKron.hpp:609
Context struct for the KronSumShell matrix.
Definition: DMRGKron.hpp:37
PetscInt NumStatesRight() const
Gets the number of states for the right block.
Definition: DMRGKron.hpp:606
Side_t
Identifies the sides of the DMRG block.
Definition: DMRGBlock.hpp:44
This site was generated by Sphinx using Doxygen with a customized theme from doxygen-bootstrapped.