TBTK
Need a break? Support the development by playing Polarity Puzzles
TBTK::Property::AbstractProperty< DataType > Class Template Reference

Abstract Property class. More...

#include <AbstractProperty.h>

Inheritance diagram for TBTK::Property::AbstractProperty< DataType >:
TBTK::Property::Property TBTK::Serializable TBTK::Streamable TBTK::Property::EnergyResolvedProperty< DataType >

Public Member Functions

unsigned int getBlockSize () const
 
unsigned int getSize () const
 
const std::vector< DataType > & getData () const
 
std::vector< DataType > & getDataRW ()
 
unsigned int getDimensions () const
 
std::vector< int > getRanges () const
 
int getOffset (const Index &index) const
 
const IndexDescriptorgetIndexDescriptor () const
 
bool contains (const Index &index) const
 
void reduce (const std::vector< Index > &targetPatterns, const std::vector< Index > &newPatterns)
 
void hermitianConjugate ()
 
std::vector< SparseMatrix< DataType > > toSparseMatrices (const Model &model) const
 
virtual const DataType & operator() (const Index &index, unsigned int offset=0) const
 
virtual DataType & operator() (const Index &index, unsigned int offset=0)
 
DataType & operator() (const std::initializer_list< Subindex > &index)
 
const DataType & operator() (const std::initializer_list< Subindex > &index) const
 
virtual const DataType & operator() (unsigned int offset) const
 
virtual DataType & operator() (unsigned int offset)
 
void setAllowIndexOutOfBoundsAccess (bool allowIndexOutOfBoundsAccess)
 
void setDefaultValue (const DataType &defaultValue)
 
void replaceValues (const DataType &targetValue, const DataType &replacementValue)
 
virtual std::string toString () const
 
virtual std::string serialize (Mode mode) const
 
- Public Member Functions inherited from TBTK::Serializable
template<>
std::string serialize (const bool &data, Mode mode)
 
template<>
std::string serialize (const double &data, Mode mode)
 
template<>
std::string serialize (const std::complex< double > &data, Mode mode)
 
template<>
std::string serialize (const int &data, Mode mode)
 
template<>
std::string serialize (const unsigned int &data, Mode mode)
 
template<>
std::string serialize (const SpinMatrix &data, Mode mode)
 
template<>
std::string serialize (const Statistics &data, Mode mode)
 
template<>
std::string serialize (const std::vector< std::complex< double >> &data, Mode mode)
 
template<>
int deserialize (const std::string &serialization, Mode mode)
 

Protected Member Functions

 AbstractProperty ()
 
 AbstractProperty (unsigned int blockSize)
 
 AbstractProperty (unsigned int blockSize, const DataType *data)
 
 AbstractProperty (const std::vector< int > &ranges, unsigned int blockSize)
 
 AbstractProperty (const std::vector< int > &ranges, unsigned int blockSize, const DataType *data)
 
 AbstractProperty (const IndexTree &indexTree, unsigned int blockSize)
 
 AbstractProperty (const IndexTree &indexTree, unsigned int blockSize, const DataType *data)
 
 AbstractProperty (const AbstractProperty &abstractProperty)
 
 AbstractProperty (AbstractProperty &&abstractProperty)
 
 AbstractProperty (const std::string &serialization, Mode mode)
 
virtual ~AbstractProperty ()
 
AbstractPropertyoperator= (const AbstractProperty &abstractProperty)
 
AbstractPropertyoperator= (AbstractProperty &&abstractProperty)
 
AbstractPropertyoperator+= (const AbstractProperty &rhs)
 
AbstractPropertyoperator-= (const AbstractProperty &rhs)
 
AbstractPropertyoperator*= (const DataType &rhs)
 
AbstractPropertyoperator/= (const DataType &rhs)
 
- Protected Member Functions inherited from TBTK::Property::Property
 Property ()
 
virtual ~Property ()
 

Additional Inherited Members

- Public Types inherited from TBTK::Serializable
enum  Mode { Debug, Binary, XML, JSON }
 
- Static Public Member Functions inherited from TBTK::Serializable
static bool hasID (const std::string &serialization, Mode mode)
 
static std::string getID (const std::string &serialization, Mode mode)
 
static std::string extractComponent (const std::string &serialization, const std::string &containerID, const std::string &componentID, const std::string &componentName, Mode mode)
 
- Static Protected Member Functions inherited from TBTK::Serializable
static bool validate (const std::string &serialization, const std::string &id, Mode mode)
 
static std::string getContent (const std::string &serialization, Mode mode)
 
static std::vector< std::string > split (const std::string &content, Mode mode)
 
template<typename DataType >
static std::enable_if<!std::is_pointer< DataType >::value, std::string >::type serialize (const DataType &data, Mode mode)
 
template<typename DataType >
static std::enable_if< std::is_pointer< DataType >::value, std::string >::type serialize (const DataType &data, Mode mode)
 
template<typename DataType >
static DataType deserialize (const std::string &serialization, Mode mode)
 
static std::string extract (const std::string &serialization, Mode mode, std::string component)
 

Detailed Description

template<typename DataType>
class TBTK::Property::AbstractProperty< DataType >

Abstract Property class.

The AbstractProperty provides a generic storage structure for the property classes that inherit from it. For more information about specific Properties, see:

Custom storage structure

There are three different layers at which the storage structure can be customized to suit the needs for the specific property: the DataType, the block size, and the Index structure.

DataType

The DataType determines the data type of the individual data elements.

Block size

The data is group into blocks of equal size. It is up to the individual properties to determine the internal structure of these blocks. For example, EnergyResolvedProperties stores the data points for a range of energies in a block, while the Density has a single element per block.

Index structure

The Index structure determines how blocks are organized and accessed as a function of Indices.

IndexDescriptor::Format::None

Used for properties that has no Index structure. For example, the DOS.

IndexDescriptor::Format::Ranges

Used to store properties on a regular grid. It imposes an array like structure on the data that is easy to export to other softwares using, for example, the FileWriter.

IndexDescriptor::Format::Custom

Used to store properties for arbitrary combinations of Indices. When the Custom format is used, the data can be accessed using the function notation property(index) or property(index, n). Here index is an Index that selects a block, while n is a number that indexes into the given block.

Out-of-bounds access

By default, it is an error to access property(index, n) if the Index index is not included in the property. However, it is possible to configure the property such that out-of-bounds access is allowed. To allow for this we call

property.setAllowIndexOutOfBoundsAccess(true);
property.setDefaultValue(defaultValue);

The last call specifies the value to return when out-of-bounds access occurs.

It is recommended to not use out-of-bounds access frivolously since out-of-bounds access typically is a sign of an error in the code. Enabling out-of-bounds access can therefore mask faulty behavior.

Constructor & Destructor Documentation

◆ AbstractProperty() [1/10]

template<typename DataType >
TBTK::Property::AbstractProperty< DataType >::AbstractProperty
protected

Constructs an uninitialized AbstractProperty.

◆ AbstractProperty() [2/10]

template<typename DataType >
TBTK::Property::AbstractProperty< DataType >::AbstractProperty ( unsigned int  blockSize)
protected

Constructs an AbstractProperty with a single data block (i.e. no Index structure).

Parameters
blockSizeThe number of data elements in the block.

◆ AbstractProperty() [3/10]

template<typename DataType >
TBTK::Property::AbstractProperty< DataType >::AbstractProperty ( unsigned int  blockSize,
const DataType *  data 
)
protected

Constructs an AbstractProperty with a single data block (i.e. no Index structure) and fills the internal memory with the data provided as input.

Parameters
blockSizeThe number of data elements in the block.
dataThe data stored on the raw format described in the detailed description of the class.

◆ AbstractProperty() [4/10]

template<typename DataType >
TBTK::Property::AbstractProperty< DataType >::AbstractProperty ( const std::vector< int > &  ranges,
unsigned int  blockSize 
)
protected

Constructs an AbstractProperty with the Ranges format.

Parameters
rangesA list of upper limits for the ranges of the different dimensions. The nth dimension will have the range [0, ranges[n]).
blockSizeThe number of data elements per block.

◆ AbstractProperty() [5/10]

template<typename DataType >
TBTK::Property::AbstractProperty< DataType >::AbstractProperty ( const std::vector< int > &  ranges,
unsigned int  blockSize,
const DataType *  data 
)
protected

Constructs an AbstractProperty with the Ranges format and fills the internal memory with the data provided as input.

Parameters
rangesA list of upper limits for the ranges of the different dimensions. The nth dimension will have the range [0, ranges[n]).
blockSizeThe number of data elements per block.
dataThe data stored on the raw format described in the detailed description of the class.

◆ AbstractProperty() [6/10]

template<typename DataType >
TBTK::Property::AbstractProperty< DataType >::AbstractProperty ( const IndexTree indexTree,
unsigned int  blockSize 
)
protected

Constructs and AbstractProperty with the Custom format.

Parameters
indexTreeIndexTree containing the Indices that the AbstractProperty should contain data for.
blockSizeThe number of data elements per block.

◆ AbstractProperty() [7/10]

template<typename DataType >
TBTK::Property::AbstractProperty< DataType >::AbstractProperty ( const IndexTree indexTree,
unsigned int  blockSize,
const DataType *  data 
)
protected

Constructs and AbstractProperty with the Custom format.

Parameters
indexTreeIndexTree containing the Indices that the AbstractProperty should contain data for.
blockSizeThe number of data elements per block.
dataThe data stored on the raw format described in the detailed description of the class.

◆ AbstractProperty() [8/10]

template<typename DataType >
TBTK::Property::AbstractProperty< DataType >::AbstractProperty ( const AbstractProperty< DataType > &  abstractProperty)
protected

Copy constructor.

Parameters
abstractPropertyAbstractProperty to copy.

◆ AbstractProperty() [9/10]

template<typename DataType >
TBTK::Property::AbstractProperty< DataType >::AbstractProperty ( AbstractProperty< DataType > &&  abstractProperty)
protected

Move constructor.

Parameters
abstractPropertyAbstractProperty to move.

◆ AbstractProperty() [10/10]

template<typename DataType >
TBTK::Property::AbstractProperty< DataType >::AbstractProperty ( const std::string &  serialization,
Mode  mode 
)
inlineprotected

Constructor. Constructs the AbstractProperty from a serialization string.

Parameters
serializationSerialization string from which to construct the AbstractProperty.
modeMode with which the string has been serialized.

◆ ~AbstractProperty()

template<typename DataType >
TBTK::Property::AbstractProperty< DataType >::~AbstractProperty
inlineprotectedvirtual

Destructor.

Member Function Documentation

◆ contains()

template<typename DataType >
bool TBTK::Property::AbstractProperty< DataType >::contains ( const Index index) const
inline

Returns true if the property contains data for the given index. [Only works for the Custom format.]

Parameters
indexIndex to check.

@raturn True if the Property contains data for the given Index.

◆ getBlockSize()

template<typename DataType >
unsigned int TBTK::Property::AbstractProperty< DataType >::getBlockSize
inline

Get block size.

Returns
The size per block.

◆ getData()

template<typename DataType >
const std::vector< DataType > & TBTK::Property::AbstractProperty< DataType >::getData
inline

Get data.

Returns
The data on the raw format described in the detailed description.

◆ getDataRW()

template<typename DataType >
std::vector< DataType > & TBTK::Property::AbstractProperty< DataType >::getDataRW
inline

Get data. Same as AbstractProperty::getData(), but with write access.

Returns
The data on the raw format described in the detailed description.

◆ getDimensions()

template<typename DataType >
unsigned int TBTK::Property::AbstractProperty< DataType >::getDimensions
inline

Get the dimension of the data. [Only works for the Ranges format.]

Returns
The dimension of the grid that the data is calculated on.

◆ getIndexDescriptor()

template<typename DataType >
const IndexDescriptor & TBTK::Property::AbstractProperty< DataType >::getIndexDescriptor
inline

Get IndexDescriptor.

Returns
The IndexDescriptor that is used internally to handle the different formats.

◆ getOffset()

template<typename DataType >
int TBTK::Property::AbstractProperty< DataType >::getOffset ( const Index index) const
inline

Get the memory offset that should be used to access the raw data for the given Index. [Only works for the Custom format.]

Parameters
indexIndex for which to get the offset.
Returns
The memory offset for the given Index.

◆ getRanges()

template<typename DataType >
std::vector< int > TBTK::Property::AbstractProperty< DataType >::getRanges
inline

Get the ranges for the dimensions of the density. [Only works for the Ranges format.]

Returns
A list of ranges for the different dimensions of the grid the data is calculated on.

◆ getSize()

template<typename DataType >
unsigned int TBTK::Property::AbstractProperty< DataType >::getSize
inline

Get size.

Returns
The total number of data elements in the Property. I.e. the number of blocks times the block size.

◆ hermitianConjugate()

template<typename DataType >
void TBTK::Property::AbstractProperty< DataType >::hermitianConjugate
inline

Turns the property into its Hermitian conjugate. Only works for the format Format::Custom. The Index structure also need to be such that every Index is a composit Index with two component Indices.

◆ operator()() [1/6]

template<typename DataType >
DataType & TBTK::Property::AbstractProperty< DataType >::operator() ( const Index index,
unsigned int  offset = 0 
)
inlinevirtual

Function call operator. Returns the data element for the given Index and offset. By default the Property does not accept Indices that are not contained in the Property. However, AbstractProperty::setAllowIndexOutOfBounds(true) is called the Property will return the value set by a call to AbstractProperty::setDefaultVlue(). Note that although it is safe to write to out of bounds elements, doing so does not result in the value being stored in the Property. [Only works for Format::Custom].

Parameters
indexThe Index to get the data for.
offsetThe offset to apply inside the block for the given Index. If not specified, the first element is returned. The function can therefore be used without specifying the offset when Properties with only a single element per block. [Only works for the Custom format.]
Returns
The data element for the given Index and offset.

Reimplemented in TBTK::Property::WaveFunctions.

◆ operator()() [2/6]

template<typename DataType >
const DataType & TBTK::Property::AbstractProperty< DataType >::operator() ( const Index index,
unsigned int  offset = 0 
) const
inlinevirtual

Function call operator. Returns the data element for the given Index and offset. By default the Property does not accept Indices that are not contained in the Property. However, AbstractProperty::setAllowIndexOutOfBounds(true) is called the Property will return the value set by a call to AbstractProperty::setDefaultVlue(). [Only works for the Custom format.]

Parameters
indexThe Index to get the data for.
offsetThe offset to apply inside the block for the given Index. If not specified, the first element is returned. The function can therefore be used without specifying the offset when Properties with only a single element per block. [Only works for the Custom format.]
Returns
The data element for the given Index and offset.

Reimplemented in TBTK::Property::WaveFunctions.

◆ operator()() [3/6]

template<typename DataType >
DataType & TBTK::Property::AbstractProperty< DataType >::operator() ( const std::initializer_list< Subindex > &  index)
inline

Alias for operator()(const Index &index, unsigned int offset = 0). Ensures that operator()(unsigned int offset) is not called when calling the function operator default offset and a single subindex index operator()({1}). Without this {1} would be cast to 1 instead of Index({1}).

Parameters
indexThe Index to get the data for.
Returns
The data element for the given Index.

◆ operator()() [4/6]

template<typename DataType >
const DataType & TBTK::Property::AbstractProperty< DataType >::operator() ( const std::initializer_list< Subindex > &  index) const
inline

Alias for operator()(const Index &index, unsigned int offset = 0). Ensures that operator()(unsigned int offset) is not called when calling the function operator default offset and a single subindex index operator()({1}). Without this {1} would be cast to 1 instead of Index({1}).

Parameters
indexThe Index to get the data for.
Returns
The data element for the given Index.

◆ operator()() [5/6]

template<typename DataType >
DataType & TBTK::Property::AbstractProperty< DataType >::operator() ( unsigned int  offset)
inlinevirtual

Function call operator. Returns the data element for the given offset.

Parameters
offsetThe offset to apply. The offset is an index into the raw data.
Returns
The data element for the given offset.

◆ operator()() [6/6]

template<typename DataType >
const DataType & TBTK::Property::AbstractProperty< DataType >::operator() ( unsigned int  offset) const
inlinevirtual

Alias for operator()(const Index &index, unsigned int offset = 0). Ensures that operator()(unsigned int offset) is not called when calling the function operator default offset and a single subindex index operator()({1}). Without this {1} would be cast to 1 instead of Index({1}).

Parameters
indexThe Index to get the data for.
Returns
The data element for the given Index. Alias for operator()(const Index &index, unsigned int offset = 0). Ensures that operator()(unsigned int offset) is not called when calling the function operator default offset and a single subindex index operator()({1}). Without this {1} would be cast to 1 instead of Index({1}).
Parameters
indexThe Index to get the data for.
Returns
The data element for the given Index. Function call operator. Returns the data element for the given offset.
Parameters
offsetThe offset to apply. The offset is an index into the raw data.
Returns
The data element for the given offset.

◆ operator*=()

template<typename DataType >
AbstractProperty< DataType > & TBTK::Property::AbstractProperty< DataType >::operator*= ( const DataType &  rhs)
inlineprotected

Multiplication assignment operator. Child classes that want to use this function must override this function and call the parents multiplication assignment operator after having performed checks whether the multiplication is possible, and before performing the multiplication of the child class parameters.

Parameters
Thevalue to multiply the left hand side by.
Returns
The left hand side after having been multiplied by the right hand side.

◆ operator+=()

template<typename DataType >
AbstractProperty< DataType > & TBTK::Property::AbstractProperty< DataType >::operator+= ( const AbstractProperty< DataType > &  rhs)
inlineprotected

Addition assignment operator. Child classes that want to use this function must override this function and call the parents addition assignment operator after having performed checks whether the addition is possible, and before performing the addition of the child class parameters.

Parameters
TheAbstractProperty to be added to the left hand side.
Returns
The left hand side after the right hand side has been added.

◆ operator-=()

template<typename DataType >
AbstractProperty< DataType > & TBTK::Property::AbstractProperty< DataType >::operator-= ( const AbstractProperty< DataType > &  rhs)
inlineprotected

Subtraction assignment operator. Child classes that want to use this function must override this function and call the parents subtraction assignment operator after having performed checks whether the subtraction is possible, and before performing the subtraction of the child class parameters.

Parameters
TheAbstractProperty to be subtracted from the left hand side.
Returns
The left hand side after the right hand side has been subtracted.

◆ operator/=()

template<typename DataType >
AbstractProperty< DataType > & TBTK::Property::AbstractProperty< DataType >::operator/= ( const DataType &  rhs)
inlineprotected

Division assignment operator. Child classes that want to use this function must override this function and call the parents division assignment operator after having performed checks whether the division is possible, and before performing the division of the child class parameters.

Parameters
Thevalue to divide the left hand side by.
Returns
The left hand side after having been divided by the right hand side.

◆ operator=() [1/2]

template<typename DataType >
AbstractProperty< DataType > & TBTK::Property::AbstractProperty< DataType >::operator= ( AbstractProperty< DataType > &&  abstractProperty)
protected

Move assignment operator.

Parameters
rhsAbstractProperty to assign to the left hand side.
Returns
Reference to the assigned AbstractProperty.

◆ operator=() [2/2]

template<typename DataType >
AbstractProperty< DataType > & TBTK::Property::AbstractProperty< DataType >::operator= ( const AbstractProperty< DataType > &  abstractProperty)
protected

Assignment operator.

Parameters
rhsAbstractProperty to assign to the left hand side.
Returns
Reference to the assigned AbstractProperty.

◆ reduce()

template<typename DataType >
void TBTK::Property::AbstractProperty< DataType >::reduce ( const std::vector< Index > &  targetPatterns,
const std::vector< Index > &  newPatterns 
)
inline

Reduces the size of the Property by only keeping values for indices that match the given target patterns. If a matching target pattern exists for a given value, the value will be stored with an Index that matches a corresponding new pattern. E.g., assume the target patterns are { {0, IDX_ALL_0, IDX_ALL_1, IDX_ALL_1}, {1, IDX_ALL_0, IDX_ALL_0} } and the new patterns are { {0, IDX_ALL_0, IDX_ALL_1}, {1, IDX_ALL_0} }. Then the data for indices such as {0, 1, 2, 3} and {1, 2, 3} will be droped since the two last subindices are not the same, which is required by both of the target patterns. However, the data for the indices {0, 1, 2, 2} and {1, 2, 2} will be kept and available through the new indices {0, 1, 2} and {1, 2}, respectively. More specifically, {0, 1, 2, 2} match the first pattern and {1, 2, 2} matches the second pattern. {0, 1, 2, 3} is therefore kept and transformed to the form {0, IDX_ALL_0, IDX_ALL_1}, while {1, 2, 2} is kept and transformed to the form {1, IDX_ALL_0}.

Parameters
targetPatternsList of patterns for indices to keep.
newPatternsList of new patterns to convert the preserved indices to.

◆ replaceValues()

template<typename DataType >
void TBTK::Property::AbstractProperty< DataType >::replaceValues ( const DataType &  targetValue,
const DataType &  replacementValue 
)
inline

Replace all values with a given target value by a given replacement value. Can be used to for example replace NaN and inf by finite numbers.

Parameters
targetValueThe value to replace.
replacementValue.The value to replace with.

◆ serialize()

◆ setAllowIndexOutOfBoundsAccess()

template<typename DataType >
void TBTK::Property::AbstractProperty< DataType >::setAllowIndexOutOfBoundsAccess ( bool  allowIndexOutOfBoundsAccess)
inline

Set whether the access of data elements for Indices that are not contained in the Property is allowed or not when using the function operator AbstractProperty::operator(). If enabled, remember to also initialize the value that is used for out of bounds access using AbstractProperty::setDefaultValue(). [Only meaningful for the Custom format.]

Parameters
allowIndexOutOfBoundsAccessTrue to enable out of bounds access.

◆ setDefaultValue()

template<typename DataType >
void TBTK::Property::AbstractProperty< DataType >::setDefaultValue ( const DataType &  defaultValue)
inline

Set the value that is returned when accessing indices not contained in the Property using the function operator AbstractProperty::operator(). Only used if AbstractProperty::setAllowIndexOutOfBoundsAccess(true) is called. [Only meaningful for the Custom format.]

Parameters
defaultValueThe value that will be returned for out of bounds access.

◆ toSparseMatrices()

template<typename DataType >
std::vector< SparseMatrix< DataType > > TBTK::Property::AbstractProperty< DataType >::toSparseMatrices ( const Model model) const
inline

Converts the matrix to a set of SparseMatrices . This only works for Properties on the Format::Custom. In addition, the Index structure has to be such that every Index is a composit Index with exactly two component Indices.

Parameters
modelA model that determines the maping from the physical indices in the Property and the linear indices in the matrix representation.
Returns
A vector of SparseMatrices . One SparseMatrix for every block index.

◆ toString()

template<typename DataType >
std::string TBTK::Property::AbstractProperty< DataType >::toString
inlinevirtual

Implements Serializable::toString().

Implements TBTK::Streamable.


The documentation for this class was generated from the following file: