Continuum Membrane 719025a62b1e384a6ff80e2f2a223ef4012153dc
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
Matrix Class Reference

Matrix used in continuum membrane model. More...

#include <Linear_algebra.hpp>

Public Member Functions

 Matrix (const int &nrow, const int &ncol, const bool &setToZero)
 Construct a new Matrix object and initialize the members to zeros. The setToZero variable is a place holder to differentiate this function from a malloc or alloc function.
 
 Matrix ()
 Default constructor.
 
 Matrix (const int &nrow)
 Constructor for creating a Matrix with a specified number of rows and one column.
 
 Matrix (const int &nrow, const int &ncol)
 Constructor for creating a Matrix with a specified number of rows and columns.
 
 Matrix (const Matrix &mat_src)
 Copy constructor for creating a deep copy of a Matrix object.
 
 Matrix (const std::vector< std::vector< double > > &vec)
 Intialize a matrix with a 2d vector.
 
Matrixoperator= (const Matrix &mat_src)
 Assignment operator.
 
 ~Matrix ()
 Destructor for the Matrix class that frees the memory allocated by the mat member.
 
void free ()
 Free memory allocation for a Matrix object.
 
int nrow () const
 get number of rows
 
int ncol () const
 get number of columns
 
double get (const int &i, const int &j) const
 Get element value at i,j.
 
double operator() (const int &i, const int &j) const
 Get element value at i,j.
 
void set (const int &i, const int &j, const double &v)
 Set element value at i,j to v.
 
void set_all (const double &v)
 Set all elements to v.
 
void transpose ()
 Transpose the matrix. This overwrites the original matrix.
 
void set_identity ()
 Set the matrix to identity matrix.
 
Matrix get_row (const int &irow) const
 Get the row vector in the format of Matrix(1, N)
 
Matrix get_col (const int &icol) const
 Get the col vector in the format of Matrix(N, 1)
 
void set_row_from_col (const int &destRow, const Matrix &srcMat, const int &srcCol)
 Set the row vector from col vector.
 
Matrix get_transposed () const
 Get the tranposed matrix.
 
void get_inverted (Matrix &matInverted)
 This function uses cholesky decomposition to solve for the inverse of the input square matrix. https://www.gnu.org/software/gsl/doc/html/linalg.html#c.gsl_linalg_cholesky_decomp1.
 
double calculate_norm () const
 Calculates the Euclidean norm of the member matrix mat.
 
double calculate_quad () const
 Calculates the Euclidean quadrance of the member matrix mat.
 

Public Attributes

gsl_matrix * mat
 

Detailed Description

Matrix used in continuum membrane model.

This class represents a N x M matrix. This header is an interface that can be implemented differently to support the use of different linear algebra pacakages. Currently gsl_blas is used for matrix calculation. Note that it is important to double check the destructor ~Matrix() and assign operator (operator=) if you would like to customize an implementation. Be careful of double free and memory leak that might be caused by misuse of pointers.

Note
To keep all the matrices definition consistent, all the coordinates and forces will be defined as 3 x 1 column vectors.

Constructor & Destructor Documentation

◆ Matrix() [1/6]

Matrix::Matrix ( const int &  nrow,
const int &  ncol,
const bool &  setToZero 
)

Construct a new Matrix object and initialize the members to zeros. The setToZero variable is a place holder to differentiate this function from a malloc or alloc function.

Parameters
nrow
ncol
setToZero

◆ Matrix() [2/6]

Matrix::Matrix ( )

Default constructor.

◆ Matrix() [3/6]

Matrix::Matrix ( const int &  nrow)

Constructor for creating a Matrix with a specified number of rows and one column.

This constructor creates a new Matrix object with the specified number of rows and one column. The elements of the matrix are uninitialized and may contain garbage values.

Parameters
nrowThe number of rows in the matrix

◆ Matrix() [4/6]

Matrix::Matrix ( const int &  nrow,
const int &  ncol 
)

Constructor for creating a Matrix with a specified number of rows and columns.

This constructor creates a new Matrix object with the specified number of rows and columns. The elements of the matrix are uninitialized and may contain garbage values.

Parameters
nrowThe number of rows in the matrix
ncolThe number of columns in the matrix

◆ Matrix() [5/6]

Matrix::Matrix ( const Matrix mat_src)

Copy constructor for creating a deep copy of a Matrix object.

This constructor creates a new Matrix object that is a deep copy of the specified Matrix object. All elements of the original matrix are copied to the new matrix, so the two matrices are completely independent.

Parameters
mat_srcThe Matrix object to be copied

◆ Matrix() [6/6]

Matrix::Matrix ( const std::vector< std::vector< double > > &  vec)

Intialize a matrix with a 2d vector.

◆ ~Matrix()

Matrix::~Matrix ( )

Destructor for the Matrix class that frees the memory allocated by the mat member.

A destructor is a special member function of a C++ class that is called automatically when an object of the class goes out of scope or is otherwise destroyed. The purpose of the destructor is to release any resources or memory that the object was holding onto, to ensure that there are no memory leaks or other resource leaks caused by the object's destruction.

Member Function Documentation

◆ calculate_norm()

double Matrix::calculate_norm ( ) const

Calculates the Euclidean norm of the member matrix mat.

◆ calculate_quad()

double Matrix::calculate_quad ( ) const

Calculates the Euclidean quadrance of the member matrix mat.

◆ free()

void Matrix::free ( )

Free memory allocation for a Matrix object.

◆ get()

double Matrix::get ( const int &  i,
const int &  j 
) const

Get element value at i,j.

◆ get_col()

Matrix Matrix::get_col ( const int &  icol) const

Get the col vector in the format of Matrix(N, 1)

Parameters
icol
Returns
Matrix

◆ get_inverted()

void Matrix::get_inverted ( Matrix matInverted)

This function uses cholesky decomposition to solve for the inverse of the input square matrix. https://www.gnu.org/software/gsl/doc/html/linalg.html#c.gsl_linalg_cholesky_decomp1.

Parameters
matrix
Returns
Matrix

◆ get_row()

Matrix Matrix::get_row ( const int &  irow) const

Get the row vector in the format of Matrix(1, N)

Parameters
irow
Returns
Matrix

◆ get_transposed()

Matrix Matrix::get_transposed ( ) const

Get the tranposed matrix.

Returns
Matrix

◆ ncol()

int Matrix::ncol ( ) const

get number of columns

◆ nrow()

int Matrix::nrow ( ) const

get number of rows

◆ operator()()

double Matrix::operator() ( const int &  i,
const int &  j 
) const

Get element value at i,j.

◆ operator=()

Matrix & Matrix::operator= ( const Matrix mat_src)

Assignment operator.

Parameters
mat_src
Returns
Matrix&

◆ set()

void Matrix::set ( const int &  i,
const int &  j,
const double &  v 
)

Set element value at i,j to v.

◆ set_all()

void Matrix::set_all ( const double &  v)

Set all elements to v.

◆ set_identity()

void Matrix::set_identity ( )

Set the matrix to identity matrix.

Note
This function checks whether the matrix is a square matrix and will throw error if the matrix is not square

◆ set_row_from_col()

void Matrix::set_row_from_col ( const int &  destRow,
const Matrix srcMat,
const int &  srcCol 
)

Set the row vector from col vector.

Parameters
irow
Returns
Matrix

◆ transpose()

void Matrix::transpose ( )

Transpose the matrix. This overwrites the original matrix.

Note
Use if the source matrix is needed.

Member Data Documentation

◆ mat

gsl_matrix* Matrix::mat

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