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 
53  virtual void setEnergyWindow(
54  double lowerBound,
55  double upperBound,
57  );
58 
84  Index pattern,
85  Index ranges
86  );
87 
90  std::initializer_list<Index> patterns
91  );
92 
128  Index pattern,
129  Index ranges
130  );
131 
134  std::initializer_list<Index> patterns
135  );
136 
160  virtual Property::LDOS calculateLDOS(Index pattern, Index ranges);
161 
164  std::initializer_list<Index> patterns
165  );
166 
208  Index pattern,
209  Index ranges
210  );
211 
214  std::initializer_list<Index> patterns
215  );
216 
218  virtual std::complex<double> calculateExpectationValue(
219  Index to,
220  Index from
221  );
222 
224  virtual Property::DOS calculateDOS();
225 
227  virtual double calculateEntropy();
228 protected:
230  static constexpr int ENERGY_RESOLUTION = 1000;
231 
234 
236  static constexpr double LOWER_BOUND = -1.;
237 
239  double lowerBound;
240 
242  static constexpr double UPPER_BOUND = 1.;
243 
245  double upperBound;
246 
249  void calculate(
250  void (*callback)(
251  PropertyExtractor *cb_this,
252  void *memory,
253  const Index &index,
254  int offset
255  ),
256  void *memory,
257  Index pattern,
258  const Index &ranges,
259  int currentOffset,
260  int offsetMultiplier
261  );
262 
266  template<typename DataType>
267  void calculate(
268  void (*callback)(
269  PropertyExtractor *cb_this,
270  void *memory,
271  const Index &index,
272  int offset
273  ),
274  const IndexTree &allIndices,
275  const IndexTree &memoryLayout,
276  Property::AbstractProperty<DataType> &abstractProperty,
277  int *spinIndexHint = nullptr
278  );
279 
282  void *hint;
283 
286  void ensureCompliantRanges(const Index &pattern, Index &ranges);
287 
289  void getLoopRanges(
290  const Index &pattern,
291  const Index &ranges,
292  int *lDimensions,
293  int **lRanges
294  );
295 
298  std::initializer_list<Index> patterns,
299  const HoppingAmplitudeSet &hoppingAmplitudeSet,
300  bool keepSumationWildcards,
301  bool keepSpinWildcards
302  );
303 };
304 
305 template<typename DataType>
307  void (*callback)(
308  PropertyExtractor *cb_this,
309  void *memory,
310  const Index &index,
311  int offset
312  ),
313  const IndexTree &allIndices,
314  const IndexTree &memoryLayout,
315  Property::AbstractProperty<DataType> &abstractProperty,
316  int *spinIndexHint
317 ){
318 /* IndexTree::Iterator it = allIndices.begin();
319  const Index *index;
320 // int counter = 0;
321  while((index = it.getIndex())){
322  if(spinIndexHint != nullptr){
323  std::vector<unsigned int> spinIndices = memoryLayout.getSubindicesMatching(
324  IDX_SPIN,
325  *index,
326  IndexTree::SearchMode::MatchWildcards
327  );
328  TBTKAssert(
329  spinIndices.size() == 1,
330  "PropertyExtractor::calculate()",
331  "Zero or several spin indeces found.",
332  "Use IDX_SPIN once and only once per pattern to indicate spin index."
333  );
334  *spinIndexHint = spinIndices.at(0);
335  }
336 
337  callback(
338  this,
339  abstractProperty.getDataRW(),
340  *index,
341  abstractProperty.getOffset(*index)
342  );
343 
344  it.searchNext();
345  }*/
346  IndexTree::Iterator it = allIndices.begin();
347  while(!it.getHasReachedEnd()){
348  Index index = it.getIndex();
349  if(spinIndexHint != nullptr){
350  std::vector<unsigned int> spinIndices = memoryLayout.getSubindicesMatching(
351  IDX_SPIN,
352  index,
353  IndexTree::SearchMode::MatchWildcards
354  );
355  TBTKAssert(
356  spinIndices.size() == 1,
357  "PropertyExtractor::calculate()",
358  "Zero or several spin indeces found.",
359  "Use IDX_SPIN once and only once per pattern to indicate spin index."
360  );
361  *spinIndexHint = spinIndices.at(0);
362  }
363 
364  callback(
365  this,
366  abstractProperty.getDataRW(),
367  index,
368  abstractProperty.getOffset(index)
369  );
370 
371  it.searchNext();
372  }
373 }
374 
375 }; //End of namespace PropertyExtractor
376 }; //End of namespace TBTK
377 
378 #endif
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
double upperBound
Definition: PropertyExtractor.h:245
Flexible physical index.
HoppingAmplitude container.
Definition: HoppingAmplitudeSet.h:49
virtual std::complex< double > calculateExpectationValue(Index to, Index from)
Property container for magnetization.
Definition: Magnetization.h:35
Property container for local density of states (LDOS).
bool getHasReachedEnd() const
Definition: IndexTree.h:194
void getLoopRanges(const Index &pattern, const Index &ranges, int *lDimensions, int **lRanges)
int energyResolution
Definition: PropertyExtractor.h:233
double lowerBound
Definition: PropertyExtractor.h:239
virtual void setEnergyWindow(double lowerBound, double upperBound, int energyResolution)
std::vector< unsigned int > getSubindicesMatching(int i, const Index &index, SearchMode searchMode) const
IndexTree generateIndexTree(std::initializer_list< Index > patterns, const HoppingAmplitudeSet &hoppingAmplitudeSet, bool keepSumationWildcards, bool keepSpinWildcards)
HoppingAmplitude container.
virtual Property::Density calculateDensity(Index pattern, Index ranges)
Property container for spin-polarized local density of states (spin-polarized LDOS).
void ensureCompliantRanges(const Index &pattern, Index &ranges)
Property container for density.
Definition: IndexTree.h:81
virtual Property::LDOS calculateLDOS(Index pattern, Index ranges)
Property container for magnetization.
Abstract Property class.
Definition: AbstractProperty.h:41
Data structure for mapping physical indices to a linear index.
Definition: IndexTree.h:34
Flexible physical index.
Definition: Index.h:70
Definition: PropertyExtractor.h:44
Definition: ModelFactory.h:35
static constexpr double LOWER_BOUND
Definition: PropertyExtractor.h:236
DataType * getDataRW()
Definition: AbstractProperty.h:235
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).
static constexpr int ENERGY_RESOLUTION
Definition: PropertyExtractor.h:230
Property container for density of states (DOS).
Definition: DOS.h:32
Iterator begin() const
static constexpr double UPPER_BOUND
Definition: PropertyExtractor.h:242
void * hint
Definition: PropertyExtractor.h:282
const Index getIndex() const
int getOffset(const Index &index) const
Definition: AbstractProperty.h:281