TBTK
Need a break? Support the development by playing Polarity Puzzles
TBTK::SpinMatrix Class Reference

Matrix containing information about a spin. More...

#include <SpinMatrix.h>

Inheritance diagram for TBTK::SpinMatrix:
TBTK::Matrix< std::complex< double >, 2, 2 >

Public Member Functions

 SpinMatrix ()
 
 SpinMatrix (std::complex< double > value)
 
 ~SpinMatrix ()
 
SpinMatrixoperator= (std::complex< double > value)
 
SpinMatrixoperator+= (const SpinMatrix &spinMatrix)
 
SpinMatrixoperator-= (const SpinMatrix &spinMatrix)
 
double getDensity () const
 
Vector3d getSpinVector () const
 
std::string toString () const
 
- Public Member Functions inherited from TBTK::Matrix< std::complex< double >, 2, 2 >
 Matrix ()
 
 Matrix (const Matrix< std::complex< double >, ROWS, COLS > &matrix)
 
 Matrix (Matrix< std::complex< double >, ROWS, COLS > &&matrix)
 
 ~Matrix ()
 
Matrix< std::complex< double >, ROWS, COLS > & operator= (const Matrix< std::complex< double >, ROWS, COLS > &rhs)
 
Matrix< std::complex< double >, ROWS, COLS > & operator= (Matrix< std::complex< double >, ROWS, COLS > &&rhs)
 
const std::complex< double > & at (unsigned int row, unsigned int col) const
 
std::complex< double > & at (unsigned int row, unsigned int col)
 
unsigned int getNumRows () const
 
unsigned int getNumCols () const
 

Friends

std::ostream & operator<< (std::ostream &stream, const SpinMatrix &spinMatrix)
 

Detailed Description

Matrix containing information about a spin.

The SpinMatrix is a Matrix with DataType std::complex<double>. If the matrix has the form

\[ \frac{1}{2}\left[\begin{array}{cc} \rho + S_z & S_x + iS_y\\ S_x - iS_y & \rho - S_z \end{array}\right] \]

Then the SpinMatrix extends the Matrix with additional functions for extracting the density and spin-vector. Note that the SpinMatrix in principle can contain arbitrary complex entries in each position, but it is then undefined behavior to use any of the SpinMatrix functions. For such matrices, only those methods derived from Matrix<std::complex> should be used.

Note that the convention for the spin matrix is equal to \(\rho + S_x\sigma_x - S_y\sigma_y + S_z\sigma_z\) rather than \(\rho + S_x\sigma_x + S_y\sigma_y + S_z\sigma_z\). The convention follows from the SpinMatrix being used to store values of the form

\[ \left[\begin{array}{cc} \langle c_{\uparrow}^{\dagger}c_{\uparrow}\rangle & \langle c_{\uparrow}^{\dagger}c_{\downarrow}\rangle\\ \langle c_{\downarrow}^{\dagger}c_{\uparrow}\rangle & \langle c_{\downarrow}^{\dagger}c_{\downarrow}\rangle\\ \end{array}\right] \]

and these expectation values are related to \(\rho, S_x, S_y\), and \(S_z\) through

\begin{eqnarray*} \rho &=& \langle c_{\uparrow}^{\dagger}c_{\uparrow}\rangle + \langle c_{\downarrow}^{\dagger}c_{\downarrow}\rangle\\ S_x &=& \langle c_{\uparrow}^{\dagger}c_{\downarrow}\rangle + \langle c_{\downarrow}^{\dagger}c_{\uparrow}\rangle\\ S_y &=& \textrm{Im}\left( \langle c_{\uparrow}^{\dagger}c_{\downarrow}\rangle - \langle c_{\downarrow}^{\dagger}c_{\uparrow}\rangle\right)\\ S_z &=& \langle c_{\uparrow}^{\dagger}c_{\uparrow}\rangle - \langle c_{\downarrow}^{\dagger}c_{\downarrow}\rangle\\ \end{eqnarray*}

Example

#include "TBTK/SpinMatrix.h"
#include "TBTK/Streams.h"
#include "TBTK/TBTK.h"
#include <complex>
using namespace std;
using namespace TBTK;
int main(){
complex<double> i(0, 1);
double rho = 1;
double S_x = 0.1;
double S_y = 0.2;
double S_z = 0.3;
SpinMatrix spinMatrix;
spinMatrix.at(0, 0) = (rho + S_z)/2.;
spinMatrix.at(1, 0) = (S_x - i*S_y)/2.;
spinMatrix.at(0, 1) = (S_x + i*S_y)/2.;
spinMatrix.at(1, 1) = (rho - S_z)/2.;
Streams::out << spinMatrix << "\n";
Streams::out << "Density: " << spinMatrix.getDensity() << "\n";
Streams::out << "Spin vector: " << spinMatrix.getSpinVector() << "\n";
}

Output

(0.65,0) (0.05,0.1)
(0.05,-0.1) (0.35,0)
Density: 1
Spin vector: (0.1, 0.2, 0.3)

Constructor & Destructor Documentation

◆ SpinMatrix() [1/2]

TBTK::SpinMatrix::SpinMatrix ( )

Constructor.

◆ SpinMatrix() [2/2]

TBTK::SpinMatrix::SpinMatrix ( std::complex< double >  value)

Constructs a SpinMatrix with all elements set to the same value.

Parameters
valueThe value to assign each entry.

◆ ~SpinMatrix()

TBTK::SpinMatrix::~SpinMatrix ( )

Destructor.

Member Function Documentation

◆ getDensity()

double TBTK::SpinMatrix::getDensity ( ) const

Get desnity.

◆ getSpinVector()

Vector3d TBTK::SpinMatrix::getSpinVector ( ) const

Get spin direction.

◆ operator+=()

SpinMatrix& TBTK::SpinMatrix::operator+= ( const SpinMatrix spinMatrix)

Addition equality operator.

◆ operator-=()

SpinMatrix& TBTK::SpinMatrix::operator-= ( const SpinMatrix spinMatrix)

Addition equality operator.

◆ operator=()

SpinMatrix& TBTK::SpinMatrix::operator= ( std::complex< double >  value)

Assignment operator for assigning a single value to every element of the matrix.

◆ toString()

std::string TBTK::SpinMatrix::toString ( ) const

Get string representation of the SpinMatrix.

Returns
A string representation of the SpinMatrix.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  stream,
const SpinMatrix spinMatrix 
)
friend

Writes the SpinMatrix toString()-representation to a stream.

Parameters
streamThe stream to write to.
spinMatrixThe SpinMatrix to write.
Returns
Reference to the output stream just written to.

The documentation for this class was generated from the following file:
Streams.h
Streams for TBTK output.
TBTK::Matrix::at
const DataType & at(unsigned int row, unsigned int col) const
Definition: Matrix.h:374
TBTK::Initialize
void Initialize()
TBTK::SpinMatrix::SpinMatrix
SpinMatrix()
TBTK::Streams::out
static std::ostream out
Definition: Streams.h:70
TBTK::SpinMatrix
Matrix containing information about a spin.
Definition: SpinMatrix.h:82
TBTK.h
TBTK initialization.