Opm::AutoDiffMatrix Class Reference

AutoDiffMatrix is a wrapper class that optimizes matrix operations. More...

#include <AutoDiffMatrix.hpp>

Public Types

typedef std::vector< double > DiagRep
 
typedef Eigen::SparseMatrix< double > SparseRep
 

Public Member Functions

 AutoDiffMatrix ()
 Creates an empty zero matrix.
 
 AutoDiffMatrix (const int num_rows, const int num_cols)
 Creates a zero matrix with num_rows x num_cols entries.
 
 AutoDiffMatrix (const Eigen::DiagonalMatrix< double, Eigen::Dynamic > &d)
 Creates a diagonal matrix from an Eigen diagonal matrix.
 
 AutoDiffMatrix (const Eigen::SparseMatrix< double > &s)
 Creates a sparse matrix from an Eigen sparse matrix.
 
 AutoDiffMatrix (const AutoDiffMatrix &other)=default
 
AutoDiffMatrixoperator= (const AutoDiffMatrix &other)=default
 
 AutoDiffMatrix (AutoDiffMatrix &&other)
 
AutoDiffMatrixoperator= (AutoDiffMatrix &&other)
 
void swap (AutoDiffMatrix &other)
 
AutoDiffMatrix operator+ (const AutoDiffMatrix &rhs) const
 Adds two AutoDiffMatrices. More...
 
AutoDiffMatrix operator* (const AutoDiffMatrix &rhs) const
 Multiplies two AutoDiffMatrices. More...
 
AutoDiffMatrixoperator+= (const AutoDiffMatrix &rhs)
 
AutoDiffMatrixoperator-= (const AutoDiffMatrix &rhs)
 
AutoDiffMatrix operator* (const double rhs) const
 Multiplies an AutoDiffMatrix with a scalar. More...
 
AutoDiffMatrix operator/ (const double rhs) const
 Divides an AutoDiffMatrix by a scalar. More...
 
Eigen::VectorXd operator* (const Eigen::VectorXd &rhs) const
 Multiplies an AutoDiffMatrix with a vector. More...
 
template<class Scalar , int Options, class Index >
void toSparse (Eigen::SparseMatrix< Scalar, Options, Index > &s) const
 Converts the AutoDiffMatrix to an Eigen SparseMatrix.This might be an expensive operation to perform for e.g., an identity matrix or a diagonal matrix.
 
int rows () const
 Returns number of rows in the matrix.
 
int cols () const
 Returns number of columns in the matrix.
 
int nonZeros () const
 Returns number of non-zero elements in the matrix. More...
 
double coeff (const int row, const int col) const
 Returns element (row, col) in the matrix.
 
const SparseRep & getSparse () const
 Returns the sparse representation of this matrix. More...
 

Static Public Member Functions

static AutoDiffMatrix createIdentity (const int num_rows_cols)
 Creates an identity matrix with num_rows_cols x num_rows_cols entries.
 
static AutoDiffMatrix addII (const AutoDiffMatrix &lhs, const AutoDiffMatrix &rhs)
 
static AutoDiffMatrix addDI (const AutoDiffMatrix &lhs, const AutoDiffMatrix &rhs)
 
static AutoDiffMatrix addDD (const AutoDiffMatrix &lhs, const AutoDiffMatrix &rhs)
 
static AutoDiffMatrix addSI (const AutoDiffMatrix &lhs, const AutoDiffMatrix &rhs)
 
static AutoDiffMatrix addSD (const AutoDiffMatrix &lhs, const AutoDiffMatrix &rhs)
 
static AutoDiffMatrix addSS (const AutoDiffMatrix &lhs, const AutoDiffMatrix &rhs)
 
static AutoDiffMatrix mulDD (const AutoDiffMatrix &lhs, const AutoDiffMatrix &rhs)
 
static AutoDiffMatrix mulDS (const AutoDiffMatrix &lhs, const AutoDiffMatrix &rhs)
 
static AutoDiffMatrix mulSD (const AutoDiffMatrix &lhs, const AutoDiffMatrix &rhs)
 
static AutoDiffMatrix mulSS (const AutoDiffMatrix &lhs, const AutoDiffMatrix &rhs)
 

Detailed Description

AutoDiffMatrix is a wrapper class that optimizes matrix operations.

Internally, an AutoDiffMatrix can be either Zero, Identity, Diagonal, or Sparse, and we utilize this to perform faster matrix operations.

Member Function Documentation

◆ getSparse()

const SparseRep& Opm::AutoDiffMatrix::getSparse ( ) const
inline

Returns the sparse representation of this matrix.

Note that this might be an expensive operation to perform if the internal structure is not sparse.

If we are not a sparse matrix, our internal variable sparse_ is undefined, and hence changing it so that it happens to be a sparse representation of our true data does not change our true data, and hence justifies that we do not really violate the const qualifier.

◆ nonZeros()

int Opm::AutoDiffMatrix::nonZeros ( ) const
inline

Returns number of non-zero elements in the matrix.

Optimizes internally by exploiting that e.g., an n*n identity matrix has n non-zeros. Note that an n*n diagonal matrix is defined to have n non-zeros, even though several diagonal elements might be 0.0.

◆ operator*() [1/3]

AutoDiffMatrix Opm::AutoDiffMatrix::operator* ( const AutoDiffMatrix rhs) const
inline

Multiplies two AutoDiffMatrices.

Internally, this function optimizes the multiplication operation based on the structure of the matrix, e.g., multiplying M with a zero matrix will obviously yield a zero matrix.

◆ operator*() [2/3]

AutoDiffMatrix Opm::AutoDiffMatrix::operator* ( const double  rhs) const
inline

Multiplies an AutoDiffMatrix with a scalar.

Optimizes internally by exploiting that e.g., an identity matrix multiplied by a scalar x yields a diagonal matrix with x the diagonal.

◆ operator*() [3/3]

Eigen::VectorXd Opm::AutoDiffMatrix::operator* ( const Eigen::VectorXd &  rhs) const
inline

Multiplies an AutoDiffMatrix with a vector.

Optimizes internally by exploiting that e.g., an identity matrix multiplied by a vector yields the vector itself.

◆ operator+()

AutoDiffMatrix Opm::AutoDiffMatrix::operator+ ( const AutoDiffMatrix rhs) const
inline

Adds two AutoDiffMatrices.

Internally, this function optimizes the addition operation based on the structure of the matrix, e.g., adding two zero matrices will obviously yield a zero matrix, and so on.

◆ operator/()

AutoDiffMatrix Opm::AutoDiffMatrix::operator/ ( const double  rhs) const
inline

Divides an AutoDiffMatrix by a scalar.

Optimizes internally by exploiting that e.g., an identity matrix divided by a scalar x yields a diagonal matrix with 1/x on the diagonal.


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