Cantera  4.0.0a1
Loading...
Searching...
No Matches
Array2D Class Reference

A class for 2D arrays stored in column-major (Fortran-compatible) form. More...

#include <Array.h>

Inheritance diagram for Array2D:
[legend]

Detailed Description

A class for 2D arrays stored in column-major (Fortran-compatible) form.

In this form, the data entry for an n row, m col matrix is

  index = i + (n-1) * j

where

J(i,j) = data_start + index
    i = row
    j = column

Definition at line 31 of file Array.h.

Public Member Functions

 Array2D ()=default
 Default constructor.
 
 Array2D (const size_t m, const size_t n, const double v=0.0)
 Constructor.
 
 Array2D (const size_t m, const size_t n, span< const double > values)
 Constructor.
 
 Array2D (const Array2D &y)
 
Array2Doperator= (const Array2D &y)
 
virtual void resize (size_t n, size_t m, double v=0.0)
 Resize the array, and fill the new entries with 'v'.
 
void appendColumn (span< const double > c)
 Append a column to the existing matrix using a std vector.
 
void setRow (size_t n, span< const double > rw)
 Set the nth row to array rw.
 
void getRow (size_t n, span< double > rw) const
 Get the nth row and return it in a vector.
 
void setColumn (size_t m, span< const double > col)
 Set the values in column m to those in array col.
 
void getColumn (size_t m, span< double > col) const
 Get the values in column m.
 
void zero ()
 Set all of the entries to zero.
 
double & operator() (size_t i, size_t j)
 Allows setting elements using the syntax A(i,j) = x.
 
double operator() (size_t i, size_t j) const
 Allows retrieving elements using the syntax x = A(i,j).
 
double & value (size_t i, size_t j)
 Returns a changeable reference to position in the matrix.
 
double value (size_t i, size_t j) const
 Returns the value of a single matrix entry.
 
size_t nRows () const
 Number of rows.
 
size_t nColumns () const
 Number of columns.
 
vector< double > & data ()
 Return a reference to the data vector.
 
const vector< double > & data () const
 Return a const reference to the data vector.
 
void operator*= (double a)
 
span< double > col (size_t j)
 Return a writable span over column j.
 
span< const double > col (size_t j) const
 Return a read-only span over column j.
 

Protected Attributes

vector< double > m_data
 Data stored in a single array.
 
size_t m_nrows = 0
 Number of rows.
 
size_t m_ncols = 0
 Number of columns.
 

Constructor & Destructor Documentation

◆ Array2D() [1/4]

Array2D ( )
default

Default constructor.

Create an empty array.

◆ Array2D() [2/4]

Array2D ( const size_t  m,
const size_t  n,
const double  v = 0.0 
)

Constructor.

Create an m by n array, and initialize all elements to v.

Parameters
mNumber of rows
nNumber of columns
vDefault fill value. The default is 0.0

Definition at line 16 of file Array.cpp.

◆ Array2D() [3/4]

Array2D ( const size_t  m,
const size_t  n,
span< const double >  values 
)

Constructor.

Create an m by n array, initialized with the contents of the array values.

Parameters
mNumber of rows
nNumber of columns
valuesInitial values of the array. Must be of length m*n, and stored in column-major order.

Definition at line 23 of file Array.cpp.

◆ Array2D() [4/4]

Array2D ( const Array2D y)

Definition at line 34 of file Array.cpp.

Member Function Documentation

◆ operator=()

Array2D & operator= ( const Array2D y)

Definition at line 41 of file Array.cpp.

◆ resize()

void resize ( size_t  n,
size_t  m,
double  v = 0.0 
)
virtual

Resize the array, and fill the new entries with 'v'.

Parameters
nThis is the number of rows
mThis is the number of columns in the new matrix
vDefault fill value -> defaults to zero.

Reimplemented in DenseMatrix.

Definition at line 52 of file Array.cpp.

◆ appendColumn()

void appendColumn ( span< const double >  c)

Append a column to the existing matrix using a std vector.

This operation will add a column onto the existing matrix.

Parameters
cThis vector is the entries in the column to be added. It must have a length equal to m_nrows or greater.

Definition at line 59 of file Array.cpp.

◆ setRow()

void setRow ( size_t  n,
span< const double >  rw 
)

Set the nth row to array rw.

Parameters
nIndex of the row to be changed
rwVector for the row. Must have a length of m_ncols.

Definition at line 69 of file Array.cpp.

◆ getRow()

void getRow ( size_t  n,
span< double >  rw 
) const

Get the nth row and return it in a vector.

Parameters
nIndex of the row to be returned.
rwReturn Vector for the operation. Must have a length of m_ncols.

Definition at line 77 of file Array.cpp.

◆ setColumn()

void setColumn ( size_t  m,
span< const double >  col 
)

Set the values in column m to those in array col.

A(i,m) = col(i)

Parameters
mColumn to set
colpointer to a col vector. Vector must have a length of m_nrows.

Definition at line 85 of file Array.cpp.

◆ getColumn()

void getColumn ( size_t  m,
span< double >  col 
) const

Get the values in column m.

col(i) = A(i,m)

Parameters
mColumn to set
colpointer to a col vector that will be returned

Definition at line 93 of file Array.cpp.

◆ zero()

void zero ( )
inline

Set all of the entries to zero.

Definition at line 118 of file Array.h.

◆ operator()() [1/2]

double & operator() ( size_t  i,
size_t  j 
)
inline

Allows setting elements using the syntax A(i,j) = x.

Parameters
irow index
jcolumn index.
Returns
a reference to A(i,j) which may be assigned.

Definition at line 128 of file Array.h.

◆ operator()() [2/2]

double operator() ( size_t  i,
size_t  j 
) const
inline

Allows retrieving elements using the syntax x = A(i,j).

Parameters
iIndex for the row to be retrieved
jIndex for the column to be retrieved.
Returns
the value of the matrix entry

Definition at line 138 of file Array.h.

◆ value() [1/2]

double & value ( size_t  i,
size_t  j 
)
inline

Returns a changeable reference to position in the matrix.

Returns a reference to the matrix's (i,j) element. This may be used as an L value.

Parameters
iThe row index
jThe column index
Returns
a changeable reference to the matrix entry

Definition at line 151 of file Array.h.

◆ value() [2/2]

double value ( size_t  i,
size_t  j 
) const
inline

Returns the value of a single matrix entry.

Returns the value of the matrix position (i,j) element.

Parameters
iThe row index
jThe column index

Definition at line 162 of file Array.h.

◆ nRows()

size_t nRows ( ) const
inline

Number of rows.

Definition at line 167 of file Array.h.

◆ nColumns()

size_t nColumns ( ) const
inline

Number of columns.

Definition at line 172 of file Array.h.

◆ data() [1/2]

vector< double > & data ( )
inline

Return a reference to the data vector.

Definition at line 177 of file Array.h.

◆ data() [2/2]

const vector< double > & data ( ) const
inline

Return a const reference to the data vector.

Definition at line 182 of file Array.h.

◆ col() [1/2]

span< double > col ( size_t  j)
inline

Return a writable span over column j.

Definition at line 189 of file Array.h.

◆ col() [2/2]

span< const double > col ( size_t  j) const
inline

Return a read-only span over column j.

Definition at line 194 of file Array.h.

Member Data Documentation

◆ m_data

vector<double> m_data
protected

Data stored in a single array.

Definition at line 200 of file Array.h.

◆ m_nrows

size_t m_nrows = 0
protected

Number of rows.

Definition at line 203 of file Array.h.

◆ m_ncols

size_t m_ncols = 0
protected

Number of columns.

Definition at line 206 of file Array.h.


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