GridFire v0.7.1_rc2
General Purpose Nuclear Network
Loading...
Searching...
No Matches
gridfire::engine::NetworkJacobian Class Reference

A wrapper class for handling the network Jacobian matrix. More...

#include <jacobian.h>

Collaboration diagram for gridfire::engine::NetworkJacobian:
[legend]

Public Member Functions

 NetworkJacobian (const Eigen::SparseMatrix< double > &jacobianMatrix, const std::function< fourdst::atomic::Species(size_t)> &indexToSpeciesFunc)
 Constructs a NetworkJacobian with the given sparse matrix and species index mapping function.
 
 NetworkJacobian (const NetworkJacobian &jacobian)
 Copy constructor for NetworkJacobian.
 
 NetworkJacobian (NetworkJacobian &&jacobian) noexcept
 Copy assignment operator for NetworkJacobian.
 
NetworkJacobianoperator= (NetworkJacobian &&jacobian) noexcept
 Move constructor for NetworkJacobian.
 
double operator() (const fourdst::atomic::Species &row, const fourdst::atomic::Species &col) const
 Accesses the value at the specified row and column corresponding to the given species.
 
double operator() (size_t i, size_t j) const
 Accesses the value at the specified row and column indices.
 
void set (const fourdst::atomic::Species &row, const fourdst::atomic::Species &col, double value)
 Sets the value at the specified row and column corresponding to the given species.
 
void set (size_t i, size_t j, double value)
 Sets the value at the specified row and column indices.
 
void set (const JacobianEntry &entry)
 Sets the value in the Jacobian matrix based on a JacobianEntry.
 
std::tuple< size_t, size_t > shape () const
 Retrieves the shape of the Jacobian matrix as a tuple (rows, columns).
 
size_t rank () const
 Retrieves the rank of the Jacobian matrix.
 
size_t nnz () const
 Get the number of non-zero entries in the Jacobian matrix.
 
bool singular () const
 Checks if the Jacobian matrix is singular.
 
std::vector< JacobianEntryinfs () const
 Retrieves all entries in the Jacobian matrix that are infinite.
 
std::vector< JacobianEntrynans () const
 Retrieves all entries in the Jacobian matrix that are NaN (Not a Number).
 
Eigen::SparseMatrix< double > data () const
 Provides access to the underlying sparse matrix data.
 
const std::unordered_map< fourdst::atomic::Species, size_t > & mapping () const
 Provides access to the species-to-index mapping.
 
void to_csv (const std::string &filename) const
 Exports the Jacobian matrix to a CSV file.
 

Private Attributes

Eigen::SparseMatrix< double > m_jacobianMatrix
 
std::unordered_map< fourdst::atomic::Species, size_t > m_speciesToIndexMap
 
std::optional< size_t > m_rank = std::nullopt
 

Detailed Description

A wrapper class for handling the network Jacobian matrix.

This class encapsulates an Eigen::SparseMatrix to represent the Jacobian matrix of a reaction network. It provides methods for accessing and modifying matrix entries using species identifiers, as well as utility functions for analyzing the matrix (e.g., checking for singularity, counting non-zero entries).

Constructor & Destructor Documentation

◆ NetworkJacobian() [1/3]

gridfire::engine::NetworkJacobian::NetworkJacobian ( const Eigen::SparseMatrix< double > &  jacobianMatrix,
const std::function< fourdst::atomic::Species(size_t)> &  indexToSpeciesFunc 
)
explicit

Constructs a NetworkJacobian with the given sparse matrix and species index mapping function.

Parameters
jacobianMatrixThe sparse matrix representing the Jacobian.
indexToSpeciesFuncA function that maps matrix indices to species identifiers.

◆ NetworkJacobian() [2/3]

gridfire::engine::NetworkJacobian::NetworkJacobian ( const NetworkJacobian jacobian)

Copy constructor for NetworkJacobian.

Parameters
jacobianThe NetworkJacobian instance to copy from.

◆ NetworkJacobian() [3/3]

gridfire::engine::NetworkJacobian::NetworkJacobian ( NetworkJacobian &&  jacobian)
noexcept

Copy assignment operator for NetworkJacobian.

Parameters
jacobianThe NetworkJacobian instance to copy from.
Returns
Reference to the assigned NetworkJacobian instance.

Member Function Documentation

◆ data()

Eigen::SparseMatrix< double > gridfire::engine::NetworkJacobian::data ( ) const

Provides access to the underlying sparse matrix data.

Returns
The Eigen::SparseMatrix representing the Jacobian.

◆ infs()

std::vector< JacobianEntry > gridfire::engine::NetworkJacobian::infs ( ) const

Retrieves all entries in the Jacobian matrix that are infinite.

Returns
A vector of JacobianEntry representing infinite entries.

◆ mapping()

const std::unordered_map< fourdst::atomic::Species, size_t > & gridfire::engine::NetworkJacobian::mapping ( ) const

Provides access to the species-to-index mapping.

Returns
A constant reference to the species-to-index mapping.

◆ nans()

std::vector< JacobianEntry > gridfire::engine::NetworkJacobian::nans ( ) const

Retrieves all entries in the Jacobian matrix that are NaN (Not a Number).

Returns
A vector of JacobianEntry representing NaN entries.

◆ nnz()

size_t gridfire::engine::NetworkJacobian::nnz ( ) const

Get the number of non-zero entries in the Jacobian matrix.

Returns
The number of non-zero entries.

◆ operator()() [1/2]

double gridfire::engine::NetworkJacobian::operator() ( const fourdst::atomic::Species &  row,
const fourdst::atomic::Species &  col 
) const

Accesses the value at the specified row and column corresponding to the given species.

Parameters
rowSpecies for the row
colSpecies for the column
Returns
value at the specified position

◆ operator()() [2/2]

double gridfire::engine::NetworkJacobian::operator() ( size_t  i,
size_t  j 
) const

Accesses the value at the specified row and column indices.

Parameters
iRow index
jColumn index
Returns
value at the specified position

◆ operator=()

NetworkJacobian & gridfire::engine::NetworkJacobian::operator= ( NetworkJacobian &&  jacobian)
noexcept

Move constructor for NetworkJacobian.

Parameters
jacobianThe NetworkJacobian instance to move from.
Returns
Reference to the assigned NetworkJacobian instance.

◆ rank()

size_t gridfire::engine::NetworkJacobian::rank ( ) const

Retrieves the rank of the Jacobian matrix.

Returns
The rank of the matrix.
Note
Rank is computed using QR decomposition and cached for efficiency. The rank is computed the first time this method is called and stored for subsequent calls. If any set operation is performed on the matrix, the cached rank is invalidated.

◆ set() [1/3]

void gridfire::engine::NetworkJacobian::set ( const fourdst::atomic::Species &  row,
const fourdst::atomic::Species &  col,
double  value 
)

Sets the value at the specified row and column corresponding to the given species.

Parameters
rowRow species
colColumn species
valueValue to set

◆ set() [2/3]

void gridfire::engine::NetworkJacobian::set ( const JacobianEntry entry)

Sets the value in the Jacobian matrix based on a JacobianEntry.

Parameters
entryThe JacobianEntry containing row species, column species, and value.

◆ set() [3/3]

void gridfire::engine::NetworkJacobian::set ( size_t  i,
size_t  j,
double  value 
)

Sets the value at the specified row and column indices.

Parameters
iRow index
jColumn index
valueValue to set

◆ shape()

std::tuple< size_t, size_t > gridfire::engine::NetworkJacobian::shape ( ) const

Retrieves the shape of the Jacobian matrix as a tuple (rows, columns).

Returns
A tuple containing the number of rows and columns.

◆ singular()

bool gridfire::engine::NetworkJacobian::singular ( ) const

Checks if the Jacobian matrix is singular.

Returns
True if the matrix is singular, false otherwise.

◆ to_csv()

void gridfire::engine::NetworkJacobian::to_csv ( const std::string &  filename) const

Exports the Jacobian matrix to a CSV file.

Parameters
filenameThe name of the CSV file to export to.

Member Data Documentation

◆ m_jacobianMatrix

Eigen::SparseMatrix<double> gridfire::engine::NetworkJacobian::m_jacobianMatrix
private

◆ m_rank

std::optional<size_t> gridfire::engine::NetworkJacobian::m_rank = std::nullopt
mutableprivate

◆ m_speciesToIndexMap

std::unordered_map<fourdst::atomic::Species, size_t> gridfire::engine::NetworkJacobian::m_speciesToIndexMap
private

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