TBTK
PropertyExtractor.h
Go to the documentation of this file.
1 /* Copyright 2016 Kristofer Bj√∂rnson
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
23 #ifndef COM_DAFER45_TBTK_PROPERTY_EXTRACTOR_PROPERTY_EXTRACTOR
24 #define COM_DAFER45_TBTK_PROPERTY_EXTRACTOR_PROPERTY_EXTRACTOR
25 
27 #include "TBTK/Index.h"
28 #include "TBTK/Property/AbstractProperty.h"
29 #include "TBTK/Property/Density.h"
30 #include "TBTK/Property/DOS.h"
31 #include "TBTK/Property/LDOS.h"
34 
35 #include <complex>
36 //#include <initializer_list>
37 
38 namespace TBTK{
39 namespace PropertyExtractor{
40 
45 public:
48 
50  virtual ~PropertyExtractor();
51 
58  virtual void setEnergyWindow(
59  double lowerBound,
60  double upperBound,
61  int energyResolution
62  );
63 
70  virtual void setEnergyInfinitesimal(double energyInfinitesimal);
71 
99  Index pattern,
100  Index ranges
101  );
102 
115 // std::initializer_list<Index> patterns
116  std::vector<Index> patterns
117  );
118 
156  Index pattern,
157  Index ranges
158  );
159 
172 // std::initializer_list<Index> patterns
173  std::vector<Index> patterns
174  );
175 
202  virtual Property::LDOS calculateLDOS(Index pattern, Index ranges);
203 
218 // std::initializer_list<Index> patterns
219  std::vector<Index> patterns
220  );
221 
266  Index pattern,
267  Index ranges
268  );
269 
284 // std::initializer_list<Index> patterns
285  std::vector<Index> patterns
286  );
287 
299  virtual std::complex<double> calculateExpectationValue(
300  Index to,
301  Index from
302  );
303 
310  virtual Property::DOS calculateDOS();
311 
318  virtual double calculateEntropy();
319 protected:
323  int getEnergyResolution() const;
324 
328  double getLowerBound() const;
329 
333  double getUpperBound() const;
334 
335  /*** Get the nergy infinitesimal.
336  *
337  * @return The energy infinitesimal. */
338  double getEnergyInfinitesimal() const;
339 
380  void calculate(
381  void (*callback)(
382  PropertyExtractor *cb_this,
383  void *memory,
384  const Index &index,
385  int offset
386  ),
387  void *memory,
388  Index pattern,
389  const Index &ranges,
390  int currentOffset,
391  int offsetMultiplier
392  );
393 
410  template<typename DataType>
411  void calculate(
412  void (*callback)(
413  PropertyExtractor *cb_this,
414  void *memory,
415  const Index &index,
416  int offset
417  ),
418  const IndexTree &allIndices,
419  const IndexTree &memoryLayout,
420  Property::AbstractProperty<DataType> &abstractProperty,
421  int *spinIndexHint = nullptr
422  );
423 
426  void *hint;
427 
434  void ensureCompliantRanges(const Index &pattern, Index &ranges);
435 
448  void getLoopRanges(
449  const Index &pattern,
450  const Index &ranges,
451  int *loopDimensions,
452  int **loopRanges
453  );
454 
477 // std::initializer_list<Index> patterns,
478  std::vector<Index> patterns,
479  const HoppingAmplitudeSet &hoppingAmplitudeSet,
480  bool keepSummationWildcards,
481  bool keepSpinWildcards
482  );
483 
495  const std::vector<Index> &patterns,
496  unsigned int expectedNumComponentIndices,
497  const std::string &functionName
498  ) const;
499 
510  const std::vector<Index> &patterns,
511  const std::vector<int> specifiers,
512  const std::string &functionName
513  ) const;
514 private:
516  static constexpr int ENERGY_RESOLUTION = 1000;
517 
519  int energyResolution;
520 
522  static constexpr double LOWER_BOUND = -1.;
523 
525  double lowerBound;
526 
528  static constexpr double UPPER_BOUND = 1.;
529 
531  double upperBound;
532 
534  static constexpr double ENERGY_INFINITESIMAL = 1e-3;
535 
538  double energyInfinitesimal;
539 };
540 
542  return energyResolution;
543 }
544 
545 inline double PropertyExtractor::getLowerBound() const{
546  return lowerBound;
547 }
548 
549 inline double PropertyExtractor::getUpperBound() const{
550  return upperBound;
551 }
552 
553 inline double PropertyExtractor::getEnergyInfinitesimal() const{
554  return energyInfinitesimal;
555 }
556 
557 template<typename DataType>
559  void (*callback)(
560  PropertyExtractor *cb_this,
561  void *memory,
562  const Index &index,
563  int offset
564  ),
565  const IndexTree &allIndices,
566  const IndexTree &memoryLayout,
567  Property::AbstractProperty<DataType> &abstractProperty,
568  int *spinIndexHint
569 ){
570  for(
571  IndexTree::ConstIterator iterator = allIndices.cbegin();
572  iterator != allIndices.end();
573  ++iterator
574  ){
575  Index index = *iterator;
576  if(spinIndexHint != nullptr){
577  std::vector<unsigned int> spinIndices = memoryLayout.getSubindicesMatching(
578  IDX_SPIN,
579  index,
580  IndexTree::SearchMode::MatchWildcards
581  );
582  TBTKAssert(
583  spinIndices.size() == 1,
584  "PropertyExtractor::calculate()",
585  "Zero or several spin indeces found.",
586  "Use IDX_SPIN once and only once per pattern to indicate spin index."
587  );
588  *spinIndexHint = spinIndices.at(0);
589  }
590 
591  callback(
592  this,
593  abstractProperty.getDataRW().data(),
594  index,
595  abstractProperty.getOffset(index)
596  );
597  }
598 }
599 
601  const std::vector<Index> &patterns,
602  unsigned int expectedNumComponentIndices,
603  const std::string &functionName
604 ) const{
605  for(unsigned int n = 0; n < patterns.size(); n++){
606  TBTKAssert(
607  patterns[n].split().size()
608  == expectedNumComponentIndices,
609  functionName,
610  "Unexpected number of pattern component Indices. The"
611  << " pattern was expected to have '"
612  << expectedNumComponentIndices << "', but the pattern"
613  << " '" << patterns[n].toString() << "' has '"
614  << patterns[n].split().size() << "' components.",
615  ""
616  );
617  }
618 }
619 
621  const std::vector<Index> &patterns,
622  const std::vector<int> specifiers,
623  const std::string &functionName
624 ) const{
625  for(unsigned int n = 0; n < patterns.size(); n++){
626  std::vector<Index> components = patterns[n].split();
627  for(unsigned int m = 0; m < components.size(); m++){
628  for(unsigned int c = 0; c < components[m].getSize(); c++){
629  int subindex = components[m][c];
630  if(subindex < 0){
631  bool isValid = false;
632  for(
633  unsigned int k = 0;
634  k < specifiers.size();
635  k++
636  ){
637  if(subindex == specifiers[k]){
638  isValid = true;
639  break;
640  }
641  }
642 
643  if(!isValid){
644  TBTKExit(
645  functionName,
646  "Invalid subindex at"
647  << " position '" << c
648  << "' in component"
649  << " Index '" << m
650  << "' of the pattern '"
651  << patterns[n].toString()
652  << "'.",
653  ""
654  );
655  }
656  }
657  }
658  }
659  }
660 }
661 
662 }; //End of namespace PropertyExtractor
663 }; //End of namespace TBTK
664 
665 #endif
double getLowerBound() const
Definition: PropertyExtractor.h:545
void validatePatternsSpecifiers(const std::vector< Index > &patterns, const std::vector< int > specifiers, const std::string &functionName) const
Definition: PropertyExtractor.h:620
void calculate(void(*callback)(PropertyExtractor *cb_this, void *memory, const Index &index, int offset), void *memory, Index pattern, const Index &ranges, int currentOffset, int offsetMultiplier)
virtual Property::SpinPolarizedLDOS calculateSpinPolarizedLDOS(Index pattern, Index ranges)
Property container for local density of states (LDOS).
Definition: LDOS.h:33
Flexible physical index.
HoppingAmplitude container.
Definition: HoppingAmplitudeSet.h:50
virtual std::complex< double > calculateExpectationValue(Index to, Index from)
Property container for magnetization.
Definition: Magnetization.h:35
ConstIterator cbegin() const
Definition: IndexTree.h:389
Property container for local density of states (LDOS).
virtual void setEnergyInfinitesimal(double energyInfinitesimal)
std::vector< DataType > & getDataRW()
Definition: AbstractProperty.h:468
double getUpperBound() const
Definition: PropertyExtractor.h:549
virtual void setEnergyWindow(double lowerBound, double upperBound, int energyResolution)
std::vector< unsigned int > getSubindicesMatching(int subindexValue, const Index &index, SearchMode searchMode) const
HoppingAmplitude container.
virtual Property::Density calculateDensity(Index pattern, Index ranges)
IndexTree generateIndexTree(std::vector< Index > patterns, const HoppingAmplitudeSet &hoppingAmplitudeSet, bool keepSummationWildcards, bool keepSpinWildcards)
Property container for spin-polarized local density of states (spin-polarized LDOS).
void ensureCompliantRanges(const Index &pattern, Index &ranges)
Property container for density.
void getLoopRanges(const Index &pattern, const Index &ranges, int *loopDimensions, int **loopRanges)
virtual Property::LDOS calculateLDOS(Index pattern, Index ranges)
Property container for magnetization.
ConstIterator end() const
Definition: IndexTree.h:393
int getEnergyResolution() const
Definition: PropertyExtractor.h:541
Data structure for mapping physical indices to linear indices.
Definition: IndexTree.h:34
Flexible physical index.
Definition: Index.h:69
Definition: IndexTree.h:287
Definition: PropertyExtractor.h:44
Definition: ModelFactory.h:35
Property container for spin-polarized local density of states (spin-polarized LDOS).
Definition: SpinPolarizedLDOS.h:37
virtual Property::Magnetization calculateMagnetization(Index pattern, Index ranges)
Property container for density.
Definition: Density.h:33
Property container for density of states (DOS).
Property container for density of states (DOS).
Definition: DOS.h:32
void * hint
Definition: PropertyExtractor.h:426
void validatePatternsNumComponents(const std::vector< Index > &patterns, unsigned int expectedNumComponentIndices, const std::string &functionName) const
Definition: PropertyExtractor.h:600
int getOffset(const Index &index) const
Definition: AbstractProperty.h:495