C++ API Reference

This reference is generated automatically from the source code via Doxygen and Breathe.

libcntr — Green’s function classes

template<typename T>
class herm_matrix

Class for two-time contour objects with hermitian symmetry.

This class contains the data structures for representing bosonic ( \(\eta = +1 \)) or fermionic ( \(\eta = -1 \)) or two-time contour functions \( C(t,t') \) and provides a number of tools to perform operations on such functions. The class herm_matrix stores the non-redundant Keldysh components

  • Matsubara component \( C^\mathrm{M}(\tau_k) \) for i=0,...,nt,

  • retarded component \( C^\mathrm{R}(t_i,t_j) \) for i=0,...,nt,j=0,...,i ,

  • lesser component \( C^<(t_j,t_i) \) for i=0,...,nt, j=0,...,i ,

  • left-mixing component \( C^\rceil(t_i,\tau_k) \) for i=0,...,nt, i=0,...,nt.

Purpose

All other Keldysh components can be expressed by the hermitian symmetries \( C^<(t_i,t_j) = - [C^<(t_j,t_i)]^\ddagger, \) \( C^\mathrm{R}(t_i,t_j) = [C^\mathrm{A}(t_j,t_i)]^\ddagger, \) \( C^\lceil(\tau_k,t_i) = -\eta [C^\rceil(t_i,\beta - \tau_k)]^\ddagger . \)

The contour function \( C(t,t') \) can be of scalar type or matrix-valued. Square-matrix-type contour functions are fully supported, while non-square- matrix contour functions are under development.

If nt = 0, only the Matsubara component is stored.

template<typename T>
class herm_matrix_timestep

Class deals with contour objects at a particular timestep .

The class ‘herm_matrix_timestep’ describes a time slice \(\mathcal{T}[C]_n\) of the contour function \(C(t,t')\) at the time step \( n \), storing \(C^<(t_j, t_n), C^\mathrm{R}(t_n, t_j)\) for \(j=0,\dots,n\) and \(C^\mathrm{M}(\tau_m), C^\rceil(t_n, \tau_m)\) for \(m=0,\dots,N_\tau\). The contour function \( C(t,t') \) can be of scalar type or matrix-valued.

Purpose

template<typename T>
class herm_matrix_timestep_view

Class serves for interfacing with class herm_matrix_timestep without copying the data.

Occasionally you may have a pre-defined object of herm_matrix or herm_matrix_timestep that you want to use. While one option is to make a copy of the data, most commonly you probably want to re-use this memory as a libcntr type, and this class serves as an interface. Mark similar concept of a map class in Eigen. To construct this class you need: a pointers to the region of memory defining different components (ret,tv,les,mat) and usual defining constants for the herm_matrix_timestep. The contour function can be of scalar type or matrix-valued.

Purpose

Square-matrix-type contour functions are fully supported, while non-square- matrix contour functions are under development. !! NOTE: MIND DANGLING POINTERS

template<typename T>
class herm_matrix_moving

Class for two-time contour objects on a memory-truncated window.

This class can represent a Green’s function in a time range \( t_0 \geq t_i \geq t_0 - t_c \). of tc timesteps backward from some leading timestep t0. The value t0 is not stored in the class.

The class herm_matrix_moving stores two non-redundant Keldysh components:

  • Retarded component \( C^\mathrm{R}(t_0-i,t_0-i-s) \) for \( i,s=0,\ldots,t_c\)

  • Lesser component \( C^<(t0-i,t_0-i-s) \) for \( i,s=0,\ldots,t_c \).

The \( C(t,t') \) can be scalar type or matrix-valued. Only square-matrix-type contour functions are fully supported.

Public Functions

void read_from_hdf5(const char *filename, const char *groupname)

Reads data from an HDF5 file with a specified filename and group name.

void read_from_hdf5(hid_t group_id)

Reads data from an HDF5 file for the specified group ID.

void read_from_hdf5(hid_t group_id, const char *groupname)

Reads data from an HDF5 file for the specified group ID and groupname.

void set_from_G_backward(const herm_pseudo<T> &g, int tstp_g)

Sets the data from a herm_matrix backward for the given timestep index tstp_g.

void set_from_G_backward(int tstp_g, const herm_pseudo<T> &g)

Sets the data from a herm_matrix backward for the given timestep index tstp_g.

void write_timestep_to_hdf5(int delti, const char *filename, const char *groupname, h5_mode mode = h5_mode::create_truncate)

Writes data to an HDF5 file with a specified filename and group name.

void write_timestep_to_hdf5(int delti, hid_t group_id)

Writes data in timeslice delti to an HDF5 file for the specified group ID in the form a timeslice.

void write_to_hdf5(const char *filename, const char *groupname, h5_mode mode = h5_mode::create_truncate)

Writes data to an HDF5 file with a specified filename and group name.

void write_to_hdf5(hid_t group_id)

Writes data to an HDF5 file for the specified group ID.

void write_to_hdf5(hid_t group_id, const char *groupname)

Writes data to an HDF5 file for the specified group ID and creating a subgroup given a name.

template<typename T>
class herm_matrix_timestep_moving

Stored tha data at one memory-truncated timeslice of a greens function.

The herm_matrix_timestep_moving represent a Greens function at physical timestep t0. Arguments of the moving timestep are understood relative to t0: this->retptr(trelj) points to G^ret(t0,t0-trelj), this->lesptr(trelj) points to G^les(t0,t0-trelj) for trelj=0,…,tc_ the pysical timestep t0 is not stored

Each element of the Greens function is a size1 x size2 matrix. Currently only size1 = size2 is supported

Template Parameters:

T – Data type (typically a numerical type like double or complex<double>).

Public Functions

void clear_timestep(void)

Clears the stored timestep data (set to zero)

inline int element_size(void) const

Returns the time elemet size = size1*size2.

inline std::complex<T> *lesptr(int deltj)

Pointer to lesser component at a given time, representing G^<(t0,t0-deltj)

void MPI_Reduce(int root)

Performs MPI reduction.

void read_from_hdf5(const char *filename, const char *groupname)

Reads data from an HDF5 file with a specified filename and group name.

void read_from_hdf5(hid_t group_id)

Reads data from an HDF5 file for the specified group ID.

inline std::complex<T> *retptr(int deltj)

Pointer to retarded component at a given time, representing G^R(t0,t0-deltj)

void set_timestep_zero(void)

Clears the stored timestep data. (set to zero)

inline int sig(void) const

Returns the statistical sign (Bose = +1, Fermi = -1).

inline int size1(void) const

Returns the number of columns.

inline int size2(void) const

Returns the number of rows (CurrentlyL always the same as number of columns!)

void smul(T alpha)

Scales the stored values by a scalar.

inline int tc(void) const

Returns the time cut-off.

void write_to_hdf5(const char *filename, const char *groupname, h5_mode mode = h5_mode::create_truncate)

Writes data to an HDF5 file with a specified filename and group name.

void write_to_hdf5(hid_t group_id)

Writes data to an HDF5 file for the specified group ID.

template<typename T>
class herm_matrix_timestep_moving_view

Class for interfacing with herm_matrix_timestep_moving without copying data.

This class provides an interface to herm_matrix_timestep_moving or herm_matrix_moving storing only pointers to the data instead of owning it. This avoids unnecessary memory duplication but requires careful handling to prevent memory errors due to raw pointer usage.

The herm_matrix_timestep_moving

represent a Greens function at physical timestep t_lead. Arguments of the moving timestep are understood relative to t_lead: this->retptr(delt) points to G^ret(t_lead,t_lead-delt),

this->lesptr(delt) points to G^les(t_lead,t_lead-delt) for delt=0,…,tc_. The pysical timestep t_lead is not stored

Each element of the Greens function is a size1 x size2 matrix. Currently only size1 = size2 is supported

Template Parameters:

T – Data type (typically a numerical type like double or complex<double>).

Public Types

typedef std::complex<T> cplx

Complex number type.

typedef T scalar_type

Scalar type.

Public Functions

inline std::complex<T> *lesptr(int deltj)

Pointer to lesser component at a given time, representing G^<(t_lead,t_lead-deltj)

void MPI_Reduce(int root)

Performs MPI reduction.

inline std::complex<T> *retptr(int deltj)

Pointer to retarded component at a given time, representing G^R(t_lead,t_lead-deltj)

inline int sig(void) const

Returns the statistical sign (Bose = +1, Fermi = -1).

inline int size1(void) const

Returns the number of columns.

inline int size2(void) const

Returns the number of rows (CurrentlyL always the same as number of columns!)

inline int tc(void) const

Returns the time cut-off.

void write_to_hdf5(const char *filename, const char *groupname, h5_mode mode = h5_mode::create_truncate)

Writes data to an HDF5 file with a specified filename and group name.

void write_to_hdf5(hid_t group_id)

Writes data to an HDF5 file for the specified group ID.

void write_to_hdf5(hid_t group_id, const char *groupname)

Writes data to an HDF5 file for the specified group ID into a subgroup with specified name.

template<typename T>
class herm_pseudo
template<typename T>
class function

Class for objects with time on real axis.

This class contains the data of a function of time on real axis. The function can be scalar/matrix valued. The class also contains various operations on functions. t = -1 means the function on the imaginary(Matsubara) axis.

Purpose

Public Members

cplx *data_

Pointer to the function in the Matrix form on the real-time axis ( ) ; ‘data_+ element_size’ corresponds to (0,0)-component of .

int nt_

Maximum number of the time steps.

int size1_

Number of the colums in the Matrix form.

int size2_

Number of the rows in the Matrix form.

int total_size_

Size of the data stored for the function on the real-time axis including ; * size1 * size2 .

template<typename T>
class function_moving

libcntr — Utility classes

template<typename T>
class cyclic_timestep

libcntr — MPI / distributed classes

template<typename T>
class distributed_array

Auxiliary data structure for handling set of data blocks and includes usual MPI processes on them.

Auxiliary data structure for handling of data blocks (total number is n_) , which are stored in contiguous form in member data_ and includes usual MPI routines. The class identity is marked by tid_ \( \in \) (0,...,ntasks_-1) and the value of the tid_ is just the MPI rank or 0 if MPI is not defined. Each data block j is owned by precisely one process, which is given by tid _map(j) = tid_. The member maxlen marks the maximum size reserved for the block. NOTE: even if the block is not owned by the process, the space for the data is allocated; the ownership plays a role when the data are manipulated

Purpose

template<typename T>
class distributed_timestep_array

Specialization of the distributed_array in which data-blocks are associated with the herm_matrix_timestep objects

Specialization of the distributed_array for the herm_matrix_timestep objects, which is used for problems, where all ranks need to have the full information [for instance spatial] about the system for a given timestep. In practice the time stepping procedure is used and the last timestep needs to be communicated between all MPI processes.

Purpose

template<typename T>
class distributed_timestep_array_moving

Specialization of the distributed_array in which data-blocks are associated with the herm_matrix_timestep_moving objects

Specialization of the distributed_array for the herm_matrix_timestep_moving objects, which is used for problems, where all ranks need to have the full information [for instance spatial] about the system for a given timestep. In practice the time stepping procedure is used and the last timestep needs to be communicated between all MPI processes.

Purpose

Steady-state routines (namespace ness2)

class herm_matrix_ness

Class representing a two-component Green’s function: retarded (ret) and lesser (les). Each component is an fft_array of size (Nft) × (size1_ × size1_).

Public Functions

void fft_to_freq()

Transform both components to the frequency domain.

void fft_to_time()

Transform both components back to the time domain.

void force_equilibrium(int bosefermi, double beta, double mu, double h)

Enforce thermal equilibrium for the lesser Green’s function.

Computes \( G^<(t) \) in thermal equilibrium for either bosons or fermions, using the fluctuation-dissipation relation and the retarded Green’s function \( G^R(t) \).

This method performs:

  • Fourier transform of \( G^R(t) \) to \( G^R(\omega) \) using FFT with step size h (equivalent to integral_transform_to_freq with FFT_TRAPEZ),

  • Constructs \( G^<(\omega) \) via:

    \[ G^<(\omega) = \mp 2i\, f(\omega - \mu)\, \mathrm{Im}\, G^R(\omega), \]
    where \( f(x) = 1 / (e^{\beta x} \pm 1) \) is the Bose-Einstein (+) or Fermi-Dirac (–) distribution,

  • Inverse FFT to obtain \( G^<(t) \).

Parameters:
  • bosefermi – Sign indicator: +1 for bosons, -1 for fermions

  • beta – Inverse temperature \( \beta \)

  • mu – Chemical potential \( \mu \)

  • h – Time step size used in the FFT

template<typename MatrixType>
void get_les(int t, MatrixType &M, fft_domain type) const

Get the lesser component of this herm_matrix_ness \( A \) at time index \( t \) (with periodic wrapping) and write to a matrix \( M \): \( M = A^<(t) \).

Template Parameters:

MatrixType – Any Eigen-compatible complex matrix type.

Parameters:
  • t – Time/freq index (wrapped periodically).

  • M – Matrix to fill with values.

  • type – Whether to read from time or frequency array (fft_domain::time or fft_domain::freq).

template<typename MatrixType>
void get_ret(int t, MatrixType &M, fft_domain type) const

Get the retarded component of this herm_matrix_ness \( A \) at time index \( t \) (with periodic wrapping) and write to a matrix \( M \): \( M = A^R(t) \).

Template Parameters:

MatrixType – Any Eigen-compatible complex matrix type.

Parameters:
  • t – Time/freq index (wrapped periodically).

  • M – Matrix to fill with values.

  • type – Whether to read from time or frequency array (fft_domain::time or fft_domain::freq).

herm_matrix_ness(const herm_matrix_ness &other)

Copy constructor.

herm_matrix_ness(int Nft = 4, int size = 1, unsigned FFTW_FLAG = FFTW_ESTIMATE)

Constructor.

Parameters:
  • Nft – Length of arrays

  • size – Logical matrix size (size × size).

  • FFTW_FLAG – Planning flag for FFTW (default: FFTW_ESTIMATE).

void incr(const herm_matrix_ness &B, cplx alpha, fft_domain type)

Increment this herm_matrix_ness \( A \) by another scaled herm_matrix_ness \( B \): \( A^{R,<} \to A^{R,<} + \alpha \cdot B^{R,<} \).

Parameters:
  • B – Another herm_matrix_ness with matching dimensions.

  • alpha – Complex scaling factor.

  • type – Whether to operate on time or frequency arrays (fft_domain::time or fft_domain::freq).

void integral_transform_to_freq(double h, fft_integral_method method = FFT_TRAPEZ)

Compute the frequency-domain Fourier integral of the retarded Green’s function.

This function computes the approximate Fourier integral

\[ G^R(\omega) = \int_0^{T} dt\, e^{i \omega t} G^R(t), \]
and
\[ G^<(\omega) = \int_{-T}^{T} dt\, e^{i \omega t} G^<(t), \]
where \( T = (N_{ft}/2- 1) \cdot h \), using either:

  • a simple discrete approximation if method=FFT_TRAPEZ} (default), and

  • a cubically corrected Fourier transform if method=FFT_CUBIC, based on Numerical Recipes (Press et al., Chapter 13.9).

The integral is computed for all frequencies \( -(N_{ft}/2-1),\dots,(N_{ft}/2-1) \) , only the Nyqusit point \( N_{ft}/2 \) is set to zero.

Parameters:
  • h – timestep

  • method – Method for calculating the integral transform (FFT_TRAPEZ default)

void integral_transform_to_time(double h, fft_integral_method method = FFT_TRAPEZ)

Compute the time-domain Fourier integral of the retarded Green’s function.

This function computes the approximate Fourier integral

\[ G^R(t) = -i\theta(t) \int_{-W}^{W} dw\, e^{-i \omega t} (-1/\pi)*ImG^R(w), \]
and
\[ G^<(t) = \int_{-W}^{W} dw\, e^{-i \omega t} G^<(w)/(2\pi) \]
where \( W = (N_{ft}/2 - 1) \cdot d\omega \), and \( d\omega=\pi/(N_{ft}/2 \cdot h) \) , and \( h \) is the timestep, using either:

  • a simple discrete approximation if method=FFT_TRAPEZ (default), and

  • a cubically corrected Fourier transform if method=FFT_CUBIC, based on Numerical Recipes (Press et al., Chapter 13.9).

Only times \( 0,...,(N_{ft}/2-1) \) are set, all others are set to zero

Parameters:
  • h – timestep

  • method – Method for calculating the DFT (FFT_TRAPEZ default)

template<typename MatrixType>
void left_multiply(const MatrixType &M, fft_domain type)

Multiply each time/frequency matrix for both ret and les of this herm_matrix_ness \( A \) from the left by a complex matrix \( M \): \( A^{R,<}(t) \to M \cdot A^{R,<}(t) \).

Template Parameters:

MatrixType – Any Eigen-compatible complex matrix type.

Parameters:
  • M – Matrix to left-multiply with.

  • type – Whether to apply to time or frequency domain data (fft_domain::time or fft_domain::freq).

template<typename MatrixType>
void left_multiply_hermconj(const MatrixType &M, fft_domain type)

Multiply each time/frequency matrix for both ret and les of this herm_matrix_ness \( A \) from the left by the hermitian conjugate of a complex matrix \( M \): \( A^{R,<}(t) \to M^\dagger \cdot A^{R,<}(t) \).

Template Parameters:

MatrixType – Any Eigen-compatible complex matrix type.

Parameters:
  • M – Matrix to left-multiply with.

  • type – Whether to apply to time or frequency domain data (fft_domain::time or fft_domain::freq).

inline fft_array &lesser()

Access the lesser component.

inline const fft_array &lesser() const

Const access to the lesser component.

herm_matrix_ness &operator=(const herm_matrix_ness &other)

Copy assignment operator.

void print_to_file(const std::string &filename, int precision = 12) const

Print the Green’s function (ret and les, time and frequency) to a text file.

Outputs:

  • Header line: # Nft size1 `precision

  • Blocks for ret_time, les_time, ret_freq, les_freq

Parameters:
  • filename – Path to the text file.

  • precision – Number of digits for real/imaginary part (default: 12).

template<typename T>
void read_from_cntr(cntr::herm_matrix<T> &Gcntr, int tstp)

Import Green’s function data from a cntr::herm_matrix at a specific time step.

This method initializes the retarded and lesser components of the Green’s function from a cntr::herm_matrix<T> at a given time step tstp. It extracts values \( G^R(t_{\text{stp}}, t_{\text{stp}} - i) \) and \( G^<(t_{\text{stp}}, t_{\text{stp}} - i) \) for all \( i \leq \min(t_{\text{stp}}, N_{\text{ft}} / 2 - 1) \), and stores them in the time-domain representation of this ness2::herm_matrix_ness object.

The lesser component is symmetrized to enforce Hermitian structure: \( G^<(-t) = -[G^<(t)]^\dagger \).

Template Parameters:

T – Scalar type of the input matrix (e.g., std::complex<double>).

Parameters:
  • Gcntr – The source Green’s function in cntr::herm_matrix<T> format.

  • tstp – The reference time step (must satisfy \( {\tt tstp} \leq \tt Gcntr.nt() \)).

Throws:

std::runtime_error – If matrix dimensions mismatch or tstp is out of range.

void read_from_file(const std::string &filename, unsigned FFTW_FLAG = FFTW_ESTIMATE)

Read the Green’s function data from a text file.

Expects the same format as produced by print_to_file. Resizes internal arrays if needed using the provided FFTW_FLAG.

Parameters:
  • filename – Path to the text file.

  • FFTW_FLAG – FFTW planning flag to use if resizing (default: `FFTW_ESTIMATE).

void read_from_hdf5(const char *filename, const char *groupname, unsigned FFTW_FLAG = FFTW_ESTIMATE)

Read Green’s function data from a given hdf5 file and group.

Opens the desired hdf5 file, reads the ret_, les_, Nft and size data from the specified group into the herm_matrix_ness object and closes the file.

Parameters:
  • filename – Name of the hdf5 file.

  • groupname – Name of the top-level group.

  • FFTW_FLAG – FFTW planning flag to use if resizing (default: FFTW_ESTIMATE).

void read_from_hdf5(hid_t group_id, const char *groupname, unsigned FFTW_FLAG = FFTW_ESTIMATE)

Helper function: Read from a named subgroup under the given hdf5 group.

Opens the specified subgroup, reads the object, and closes the subgroup.

Parameters:
  • group_id – hdf5 parent group identifier.

  • groupname – Name of the subgroup to open.

  • FFTW_FLAG – FFTW planning flag to use if resizing (default: FFTW_ESTIMATE).

void read_from_hdf5(hid_t group_id, unsigned FFTW_FLAG = FFTW_ESTIMATE)

Helper function: Read the herm_matrix_ness data (ret and les components) from an hdf5 group.

If the stored dimensions differ from the current object, automatically resizes the object using the provided FFTW_FLAG.

Parameters:
  • group_id – hdf5 group identifier.

  • FFTW_FLAG – FFTW planning flag to use if resizing (default: FFTW_ESTIMATE).

inline fft_array &retarded()

Access the retarded component.

inline const fft_array &retarded() const

Const access to the retarded component.

template<typename MatrixType>
void right_multiply(const MatrixType &M, fft_domain type)

Multiply each time/frequency matrix for both ret and les of this herm_matrix_ness \( A \) from the right by a complex matrix \( M \): \( A^{R,<}(t) \to A^{R,<}(t) \cdot M \).

Template Parameters:

MatrixType – Any Eigen-compatible complex matrix type.

Parameters:
  • M – Matrix to right-multiply with.

  • type – Whether to apply to time or frequency domain data (fft_domain::time or fft_domain::freq).

template<typename MatrixType>
void right_multiply_hermconj(const MatrixType &M, fft_domain type)

Multiply each time/frequency matrix for both ret and les of this herm_matrix_ness \( A \) from the right by the hermitian conjugate of a complex matrix \( M \): \( A^{R,<}(t) \to A^{R,<}(t) \cdot M^\dagger \).

Template Parameters:

MatrixType – Any Eigen-compatible complex matrix type.

Parameters:
  • M – Matrix to left-multiply with.

  • type – Whether to apply to time or frequency domain data (fft_domain::time or fft_domain::freq).

template<typename MatrixType>
void set_les(int t, const MatrixType &M, fft_domain type)

Set the lesser component of this herm_matrix_ness \( A \) at time index \( t \) (with periodic wrapping) from a matrix \( M \): \( A^<(t) = M \).

Template Parameters:

MatrixType – Any Eigen-compatible complex matrix type.

Parameters:
  • t – Time index (wrapped periodically).

  • M – Matrix to assign.

  • type – Whether to apply to time or frequency array (fft_domain::time or fft_domain::freq).

void set_matrixelement(int i1, int i2, const herm_matrix_ness &B, int j1, int j2, fft_domain type)

Set one matrix element (both ret and les) of this herm_matrix_ness \( A \) from another herm_matrix_ness \( B \).

This sets \( A^{R,<}(i_1, i_2)(t) = B^{R,<}(j_1, j_2)(t) \) across all times or frequencies.

Parameters:
  • i1 – Row index in \( A(i_1, i_2) \).

  • i2 – Column index in \( A(i_1, i_2) \).

  • B – Source fft_array.

  • j1 – Row index in \( B(j_1, j_2) \).

  • j2 – Column index in \( B(j_1, j_2) \).

  • type – Whether to operate on time or frequency arrays (fft_domain::time or fft_domain::freq).

template<typename MatrixType>
void set_ret(int t, const MatrixType &M, fft_domain type)

Set the retarded component of this herm_matrix_ness \( A \) at time index \( t \) (with periodic wrapping) from a matrix \( M \): \( A^R(t) = M \).

Template Parameters:

MatrixType – Any Eigen-compatible complex matrix type.

Parameters:
  • t – Time/frequency index (wrapped periodically).

  • M – Matrix to assign.

  • type – Whether to apply to time or frequency array (fft_domain::time or fft_domain::freq).

void set_zero(fft_domain type)

Set all elements of both ret and les to zero.

Parameters:

type – Whether to clear time or frequency arrays (fft_domain::time or fft_domain::freq).

void smul(cplx alpha, fft_domain type)

Scale both ret and les of this herm_matrix_ness \( A \) in-place by a complex scalar: \( A^{R,<} \to \alpha \cdot A^{R,<} \).

Parameters:
  • alpha – Complex scaling factor.

  • type – Whether to operate on time or frequency arrays (fft_domain::time or fft_domain::freq).

void write_to_hdf5(const char *filename, const char *groupname) const

Write Green’s function to a hdf5 file under the given group name.

Opens or creates the hdf5 file if not exisitng, writes theret_, les_, Nft and size data of the herm_matrix_ness under the specified group name and closes the file.

Parameters:
  • filename – Name of the hdf5 file.

  • groupname – Name of the top-level group to create.

void write_to_hdf5(hid_t group_id) const

Helper function: Write the herm_matrix_ness data (ret and les components) to an hdf5 group.

Stores attributes for Nft_ and size1_ and delegates writing to the internal fft_array instances (ret_ and les_).

Parameters:

group_id – hdf5 group identifier.

void write_to_hdf5(hid_t group_id, const char *groupname) const

Helper function: Write to a named subgroup under the given hdf5 group.

Creates a subgroup named groupname, writes this object into it, and closes it.

Parameters:
  • group_id – hdf5 parent group identifier.

  • groupname – Name of the subgroup to create.

~herm_matrix_ness()

Destructor.

Public Members

fft_array les_

Lesser component.

int Nft_

FFT length.

fft_array ret_

Retarded component.

int size1_

logical matrix size

class grid_info

Grid information for time and frequency axes associated with FFT arrays.

This class describes the time and frequency grids with steps \( h \) and \( d\omega \) and length \( N_{ft} \) used in fft_array and herm_matrix_ness.

Given:

  • h_: time step,

  • Nft_: total FFT grid points,

  • \( {\tt dw\_} = \frac{2\pi}{{\tt Nft\_} \cdot {\tt h\_}} \): frequency step.

Public Functions

double freq_at(int k) const

Get frequency value \( \omega \) at grid index \( k \): \( w = k \cdot dw \quad \text{for} \quad k=0\dots \frac{N_{ft}}{2}-1 \\ w = (k - N_{ft}) \cdot dw \quad \text{for} \quad k=\frac{N_{ft}}{2} \dots N_{ft} - 1 \).

further indices are periodically wrapped

Parameters:

k – freqeuncy grid index

std::vector<double> freq_grid() const

Generate the full wrapped frequency grid.

Returns:

vector of frequency values (length \( N_{ft} \))

grid_info(int Nft, double h)

Constructor to initialize grid with time step \( h \) and length \( N_{ft} \).

Parameters:
  • Nft – number of time points (must be positive)

  • h – time step (must be positive)

void set_dw(double new_dw)

Update frequency step \( d\omega \) and adjust time step \( h \) accordingly.

Parameters:

new_dw – new frequency step (must be positive)

void set_h(double new_h)

Update time step \( h \) and adjust frequency step \( d\omega \) accordingly.

Parameters:

new_h – new time step (must be positive)

double time_at(int n) const

Get time value \( t \) at grid index \( n \): \( t = n \cdot h \quad \text{for} \quad n=0 \dots \frac{N_{ft}}{2}-1 \\ t = (n - N_{ft}) \cdot h \quad \text{for} \quad n = \frac{N_{ft}}{2} \dots N_{ft} - 1 \).

further indices are periodically wrapped

Parameters:

n – time grid index

std::vector<double> time_grid() const

Generate the full wrapped time grid.

Returns:

vector of time values (length \( N_{ft} \))

Public Members

double dw_

frequency step

double h_

time step

int Nft_

total number of FFT grid points

class fft_array

A class that manages multiple strided FFTs using FFTW.

The data is arranged such that each FFT has stride element_size_ = size1_ * size1_, and is of length Nft. Forward and backward plans are created once and reused.

Public Functions

fft_array(const fft_array &other)

Copy constructor.

fft_array(int Nft, int size, unsigned FFTW_FLAG = FFTW_ESTIMATE)

Constructor.

Parameters:
  • Nft – FFT length

  • size – Logical size (stride = size x size)

  • FFTW_FLAG – FFTW planning flag (e.g., FFTW_ESTIMATE)

void fft_to_freq()

Performs a forward FFT (time domain → frequency domain). This is because plan_back_ was created with FFTW_FORWARD.

\( X[k] = \sum_{n=0}^{N_{ft}-1} x[n] \cdot \exp(-2\pi i \cdot k \cdot n / N_{ft}) \)

Note: This is the standard DFT definition (no scaling).

void fft_to_time()

Performs an inverse FFT (frequency domain → time domain). This is because plan_for_ was created with FFTW_BACKWARD.

\( x[n] = \sum_{k=0}^{N_{ft}-1} X[k] \cdot \exp(+2\pi i \cdot k \cdot n / N_{ft}) \)

Note: FFTW does NOT normalize this, so the result will be scaled by \( N_{ft} \) . You may need to manually divide by \( N_{ft} \) if you want the exact inverse.

void get_element(int t, cplx &val, fft_domain type) const

Get \( {\tt val} = A(t) \) from this fft_array \( A \) at time or frequency index \( t \) (with periodic wrapping).

Only valid when \( \text{size1}\_ = 1 \) (scalar case). If \( t < 0 \) or \( t \geq N_{ft} \), it is automatically wrapped periodically: \( t \equiv t \bmod N_{ft} \) in \( [0, N_{ft} - 1] \).

Parameters:
  • t – Time index (wrapped periodically).

  • val – Complex scalar to retrieve.

  • type – Whether to read from time or frequency array (fft_domain::time or fft_domain::freq).

template<typename MatrixType>
void get_element(int t, MatrixType &M, fft_domain type) const

Get \( M = A(t) \) from this fft_array \( A \) at or frequency time index \( t \) (with periodic wrapping).

If \( t < 0 \) or \( t \geq N_{ft} \), it is automatically wrapped periodically: \( t \equiv t \bmod N_{ft} \) in \( [0, N_{ft} - 1] \).

Template Parameters:

MatrixType – Any Eigen-compatible complex matrix type.

Parameters:
  • t – Time index (wrapped periodically).

  • M – Matrix to fill with the values at time index \( t \).

  • type – Whether to read from time or frequency array (fft_domain::time or fft_domain::freq).

void incr(const fft_array &B, std::complex<double> alpha, fft_domain type)

Increment this fft_array \( A \) by another scaled array \( B \): \( A \to A + \alpha \cdot B \).

Parameters:
  • B – Another fft_array with matching dimensions.

  • alpha – Complex scaling factor.

  • type – Whether to operate on time or frequency arrays (fft_domain::time or fft_domain::freq).

template<typename MatrixType>
void left_multiply(const MatrixType &M, fft_domain type)

Multiply each time/frequency matrix of this fft_array \( A \) from the left by a complex matrix \( M \): \( A(t) \to M \cdot A(t) \).

definitions of templated member functions:

Template Parameters:

MatrixType – Any Eigen-compatible complex matrix type.

Parameters:
  • M – The matrix to left-multiply with (must be size1_ × size1_)

  • type – Whether to apply to time or frequency domain data (fft_domain::time or fft_domain::freq).

template<typename MatrixType>
void left_multiply_hermconj(const MatrixType &M, fft_domain type)

Multiply each time/frequency matrix of this fft_array \( A \) from the left by the hermitian conjugate of a complex matrix \( M \): \( A(t) \to M^\dagger \cdot A(t) \).

Template Parameters:

MatrixType – Any Eigen-compatible complex matrix type.

Parameters:
  • M – The matrix to left-multiply with (must be size1_ × size1_)

  • type – Whether to apply to time or frequency domain data (fft_domain::time or fft_domain::freq).

fft_array &operator=(const fft_array &other)

Copy assignment operator.

void print_to_file(const std::string &filename, int precision = 12) const

Print the time and frequency arrays to a plain text file.

Outputs:

  • Header: # Nft size1_ precision

  • Blocks: time and frequency (each with one line per \( t \)).

Parameters:
  • filename – Path to the text file.

  • precision – Number of digits for real/imaginary part (default: 12).

void read_from_file(const std::string &filename, unsigned FFTW_FLAG = FFTW_ESTIMATE)

Read the time and frequency arrays from a plain text file written with print_to_file

Resizes internal arrays if needed using the provided FFTW_FLAG.

Parameters:
  • filename – Path to the text file.

  • FFTW_FLAG – FFTW planning flag to use if resizing (default: FFTW_ESTIMATE).

void read_from_hdf5(hid_t group_id, unsigned FFTW_FLAG = FFTW_ESTIMATE)

Read the fft_array data (time and frequency arrays) from an HDF5 group.

If the stored array dimensions differ from the current object, automatically resizes the object using the provided FFTW_FLAG.

Parameters:
  • group_id – HDF5 group identifier.

  • FFTW_FLAG – FFTW planning flag to use if resizing (default: FFTW_ESTIMATE).

void resize(int new_Nft, int new_size1, unsigned FFTW_FLAG = FFTW_ESTIMATE)

Resize the fft_array and rebuild FFTW plans.

Frees any existing memory and FFTW plans, then allocates new arrays and creates new FFTW plans for the given sizes. After calling, the array is reset and ready for use.

Parameters:
  • new_Nft – New number of time samples per transform.

  • new_size1 – New matrix dimension (new_size1 × new_size1).

  • FFTW_FLAG – FFTW planning flag (default: FFTW_ESTIMATE).

template<typename MatrixType>
void right_multiply(const MatrixType &M, fft_domain type)

Multiply each time/frequency matrix of this fft_array \( A \) from the right by a complex matrix \( M \): \( A(t) \to A(t) \cdot M \).

Template Parameters:

MatrixType – Any Eigen-compatible complex matrix type.

Parameters:
  • M – The matrix to right-multiply with (must be size1_ xsize1_)

  • type – Whether to apply to time or frequency domain data (fft_domain::time or fft_domain::freq).

template<typename MatrixType>
void right_multiply_hermconj(const MatrixType &M, fft_domain type)

Multiply each time/frequency matrix of this fft_array \( A \) from the right by the hermitian conjugate of a complex matrix \( M \): \( A(t) \to A(t) \cdot M^\dagger \).

Template Parameters:

MatrixType – Any Eigen-compatible complex matrix type.

Parameters:
  • M – The matrix to left-multiply with (must be size1_ × size1_)

  • type – Whether to apply to time or frequency domain data (fft_domain::time or fft_domain::freq).

template<typename MatrixType>
void set_element(int t, const MatrixType &M, fft_domain type)

Set this fft_array \( A \) to \( A(t) \) = \( M \) at time or frequency index \( t \) (with periodic wrapping).

If \( t < 0 \) or \( t \geq N_{ft} \), it is automatically wrapped periodically: \( t \equiv t \bmod N_{ft} \) in \( [0, N_{ft} - 1] \).

Template Parameters:

MatrixType – Any Eigen-compatible complex matrix type.

Parameters:
  • t – Time index (wrapped periodically).

  • M – Matrix to assign.

  • type – Whether to apply to time or frequency array (fft_domain::time or fft_domain::freq).

void set_element(int t, cplx val, fft_domain type)

Set this fft_array \( A \) to \( A(t) = \tt{val} \) at time or frequency index \( t \) (with periodic wrapping).

Only valid when \( \text{size1}\_ = 1 \) (scalar case). If \( t < 0 \) or \( t \geq N_{ft} \), it is automatically wrapped periodically: \( t \equiv t \bmod N_{ft} \) in \( [0, N_{ft} - 1] \).

Parameters:
  • t – Time index (wrapped periodically).

  • val – Complex scalar to assign.

  • type – Whether to apply to time or frequency array (fft_domain::time or fft_domain::freq).

void set_matrixelement(int i1, int i2, const fft_array &B, int j1, int j2, fft_domain type)

Set one matrix element’s time or frequency series of this fft_array \( A \) from another fft_array \( B \).

This sets \( A(i_1, i_2)(t) = B(j_1, j_2)(t) \) across all times or frequencies.

Parameters:
  • i1 – Row index in \( A(i_1, i_2) \).

  • i2 – Column index in \( A(i_1, i_2) \).

  • B – Source fft_array.

  • j1 – Row index in \( B(j_1, j_2) \).

  • j2 – Column index in \( B(j_1, j_2) \).

  • type – Whether to operate on time or frequency arrays (fft_domain::time or fft_domain::freq).

void set_zero(fft_domain type)

Set all elements of either the time or frequency array to zero.

Parameters:

type – Indicates whether to clear the time or frequency array.

void smul(std::complex<double> alpha, fft_domain type)

Scale this fft_array \( A \) in-place by a complex scalar \( \alpha \): \( A \to \alpha \cdot A \).

Parameters:
  • alpha – Complex scaling factor.

  • type – Indicates whether to scale time or frequency array (fft_domain::time or fft_domain::freq).

void write_to_hdf5(hid_t group_id) const

Write the fft_array data (time and frequency arrays) to an HDF5 group.

Stores attributes for Nft_, size1_, and element_size_, and datasets for the time_ and freq_ arrays as 3D arrays of shape [Nft_, size1_, size1_].

Parameters:

group_id – HDF5 group identifier.

~fft_array()

Destructor.

Public Members

int element_size_

Stride for each transform (`size1_ * size1_)

fftw_complex *freq_

Pointer to frequency-domain data.

int Nft_

Number of time samples per transform.

int size1_

Logical size (stride = size1_ * size1_)

fftw_complex *time_

Pointer to time-domain data.

class FFT_OMP_Manager

Class to manage FFTW threading setup and cleanup. Use this to initialize FFTW with threads once at program start.

Public Static Functions

static void finalize()

Clean up threading resources (call only after all plans are destroyed).

static void initialize(void)

Initialize FFTW threads (pthreads backend). \( n\) is used for plans created afterwards.

static void set_threads_for_new_plans(int n)

Change the thread count used by new plans (does not affect existing plans) to n.

class bethedos

Class represent the semicircular density of states

This class contains the data structures for representing the density of states for a Bethe semicircular with the bandwidth 4V, centered around E0

Purpose

Public Functions

bethedos(double a, double b)

DOS between a and b, i.e. center = (a+b)/2, width=(b-a)

Public Members

double hi_

Higher edge of the density of states

double lo_

Lower edge of the density of states

double V_

4V corresponds to the bandwidth

class gauss

Class represent the gaussian density of states

This class contains the data structures for representing the density of states for a gaussian with mean 0 and a standard deviation of 1.

Purpose

Public Members

double hi_

Higher edge of the density of states

double lo_

Lower edge of the density of states

double mu_

Mean of gaussian

double sigma_

Standard deviation of gaussian

class ohmic_sym

Class represents a symmetric ohmic bath x^2*exp(-x/x_c) density of states

This class contains the data structures for representing the density of states for an ohmic bath and includes a free parameter: the cutoff energy \( \omega_c \) and is adapted so the spectrum is antisymmetric (boson).

Purpose

Public Members

double hi_

Higher edge of the density of states

double lo_

Lower edge of the density of states

double omegac_

Cutoff

Steady-state routines — legacy (namespace ness)

class GF

Class represents Green’s functions in either time or frequency domain.

This class contains the data structures for representing complex matrix valued Green’s functions on a time or frequency grid, stored in two data arrays for retarded and lesser component.

Purpose

Public Functions

inline int gf_idx(int w)

Return frequency, not stored in adcending order

GF operator+(const GF &g)

Operator + for Green’s functions

GF &operator=(const GF &g)

Operator = for Green’s functions

Public Members

double dgrid_

Grid spacing

int gf_type_

Green’s function type, 0: time, 1: frequency

std::vector<Eigen::Map<Eigen::Matrix<cplx, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>> Lesser

Save raw data pointer in a nice eigen3 structure

long ngrid_

Number of grid points

std::vector<Eigen::Map<Eigen::Matrix<cplx, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>> Retarded

Save raw data pointer in a nice eigen3 structure

int sign_

Sign +1 for bosons, -1 for fermions.

int size1_

Orbital dimension 1

int size2_

Orbital dimension 2

class gauss

Class represent the gaussian density of states

This class contains the data structures for representing the density of states for a gaussian with mean mu_=0 and a standard deviation of sigma_=1.

Purpose

Public Members

double hi_

Higher edge of the density of states

double lo_

Lower edge of the density of states

double mu_

Mean of gaussian

double sigma_

Standard deviation of gaussian

class ohmic_sym

Class represents a symmetric ohmic bath density of states

This class contains the data structures for representing the density of states for an ohmic bath and includes a free parameter: the cutoff energy \( \omega_c \) and is adapted so the spectrum is antisymmetric (boson).

Purpose

Public Members

double hi_

Higher edge of the density of states

double lo_

Lower edge of the density of states

double omegac_

Cutoff