Cantera  2.1.2
Public Types | Public Member Functions | Protected Attributes | List of all members
Array2D Class Reference

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

#include <Array.h>

Inheritance diagram for Array2D:
[legend]

Public Types

typedef vector_fp::iterator iterator
 Type definition for the iterator class that is can be used by Array2D types. More...
 
typedef vector_fp::const_iterator const_iterator
 Type definition for the const_iterator class that is can be used by Array2D types. More...
 

Public Member Functions

 Array2D ()
 Default constructor. More...
 
 Array2D (const size_t m, const size_t n, const doublereal v=0.0)
 Constructor. More...
 
 Array2D (const size_t m, const size_t n, const doublereal *values)
 Constructor. More...
 
 Array2D (const Array2D &y)
 Copy constructor. More...
 
Array2Doperator= (const Array2D &y)
 assignment operator More...
 
void resize (size_t n, size_t m, doublereal v=0.0)
 Resize the array, and fill the new entries with 'v'. More...
 
void copyData (const Array2D &y)
 Copy the data from one array into another without doing any checking. More...
 
void appendColumn (const vector_fp &c)
 Append a column to the existing matrix using a std vector. More...
 
void appendColumn (const doublereal *const c)
 Append a column to the existing matrix. More...
 
void setRow (size_t n, const doublereal *const rw)
 Set the nth row to array rw. More...
 
void getRow (size_t n, doublereal *const rw)
 Get the nth row and return it in a vector. More...
 
void setColumn (size_t m, doublereal *const col)
 Set the values in column m to those in array col. More...
 
void getColumn (size_t m, doublereal *const col)
 Get the values in column m. More...
 
virtual ~Array2D ()
 Destructor. More...
 
void axpy (doublereal a, const Array2D &x, const Array2D &y)
 Evaluate z = a*x + y. More...
 
void zero ()
 Set all of the entries to zero. More...
 
doublereal & operator() (size_t i, size_t j)
 Allows setting elements using the syntax A(i,j) = x. More...
 
doublereal operator() (size_t i, size_t j) const
 Allows retrieving elements using the syntax x = A(i,j). More...
 
doublereal & value (size_t i, size_t j)
 Returns a changeable reference to position in the matrix. More...
 
doublereal value (size_t i, size_t j) const
 Returns the value of a single matrix entry. More...
 
size_t nRows () const
 Number of rows. More...
 
size_t nColumns () const
 Number of columns. More...
 
iterator begin ()
 Return an iterator pointing to the first element. More...
 
iterator end ()
 Return an iterator pointing past the last element. More...
 
const_iterator begin () const
 Return a const iterator pointing to the first element. More...
 
const_iterator end () const
 Return a const iterator pointing to past the last element. More...
 
vector_fpdata ()
 Return a reference to the data vector. More...
 
const vector_fpdata () const
 Return a const reference to the data vector. More...
 
doublereal * ptrColumn (size_t j)
 Return a pointer to the top of column j, columns are contiguous in memory. More...
 
const doublereal * ptrColumn (size_t j) const
 Return a const pointer to the top of column j, columns are contiguous in memory. More...
 

Protected Attributes

vector_fp m_data
 Data stored in a single array. More...
 
size_t m_nrows
 Number of rows. More...
 
size_t m_ncols
 Number of columns. More...
 

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 33 of file Array.h.

Member Typedef Documentation

typedef vector_fp::iterator iterator

Type definition for the iterator class that is can be used by Array2D types.

this is just equal to vector_fp iterator.

Definition at line 43 of file Array.h.

typedef vector_fp::const_iterator const_iterator

Type definition for the const_iterator class that is can be used by Array2D types.

this is just equal to vector_fp const_iterator.

Definition at line 51 of file Array.h.

Constructor & Destructor Documentation

Array2D ( )
inline

Default constructor.

Create an empty array.

Definition at line 56 of file Array.h.

Array2D ( const size_t  m,
const size_t  n,
const doublereal  v = 0.0 
)
inline

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 71 of file Array.h.

References Array2D::m_data.

Array2D ( const size_t  m,
const size_t  n,
const doublereal *  values 
)
inline

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 87 of file Array.h.

References Array2D::m_data, Array2D::m_ncols, and Array2D::m_nrows.

Array2D ( const Array2D y)
inline

Copy constructor.

Parameters
yArray2D to make the copy from

Definition at line 97 of file Array.h.

References Array2D::m_data, Array2D::m_ncols, and Array2D::m_nrows.

virtual ~Array2D ( )
inlinevirtual

Destructor.

Does nothing, since no memory allocated on the heap.

Definition at line 232 of file Array.h.

Member Function Documentation

Array2D& operator= ( const Array2D y)
inline

assignment operator

Parameters
yArray2D to get the values from

Definition at line 111 of file Array.h.

References Array2D::m_data, Array2D::m_ncols, and Array2D::m_nrows.

Referenced by DenseMatrix::operator=().

void resize ( size_t  n,
size_t  m,
doublereal  v = 0.0 
)
inline
void copyData ( const Array2D y)
inline

Copy the data from one array into another without doing any checking.

This differs from the assignment operator as no resizing is done and memcpy() is used.

Parameters
yArray to be copied

Definition at line 139 of file Array.h.

References DATA_PTR, Array2D::m_data, Array2D::m_ncols, Array2D::m_nrows, and Array2D::ptrColumn().

Referenced by SquareMatrix::copyData().

void appendColumn ( const vector_fp c)
inline

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

This operation will add a column onto the existing matrix.

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

Definition at line 152 of file Array.h.

References Array2D::m_data, Array2D::m_ncols, Array2D::m_nrows, and Array2D::value().

void appendColumn ( const doublereal *const  c)
inline

Append a column to the existing matrix.

This operation will add a column onto the existing matrix.

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

Definition at line 169 of file Array.h.

References Array2D::m_data, Array2D::m_ncols, Array2D::m_nrows, and Array2D::value().

void setRow ( size_t  n,
const doublereal *const  rw 
)
inline

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 183 of file Array.h.

References Array2D::m_data, Array2D::m_ncols, and Array2D::m_nrows.

void getRow ( size_t  n,
doublereal *const  rw 
)
inline

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 195 of file Array.h.

References Array2D::m_data, Array2D::m_ncols, and Array2D::m_nrows.

Referenced by StFlow::save().

void setColumn ( size_t  m,
doublereal *const  col 
)
inline

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 209 of file Array.h.

References Array2D::m_data, and Array2D::m_nrows.

void getColumn ( size_t  m,
doublereal *const  col 
)
inline

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 222 of file Array.h.

References Array2D::m_data, and Array2D::m_nrows.

void axpy ( doublereal  a,
const Array2D x,
const Array2D y 
)
inline

Evaluate z = a*x + y.

This function evaluates the AXPY operation, and stores the result in the object's Array2D object. It's assumed that all 3 objects have the same dimensions, but no error checking is done.

Parameters
ascalar to multiply x with
xFirst Array2D object to be used
ySecond Array2D object to be used

Definition at line 246 of file Array.h.

References Array2D::begin(), and Array2D::end().

void zero ( )
inline
doublereal& operator() ( size_t  i,
size_t  j 
)
inline

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

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

Definition at line 274 of file Array.h.

References Array2D::value().

Referenced by SquareMatrix::operator()().

doublereal 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
Returns the value of the matrix entry

Definition at line 286 of file Array.h.

References Array2D::value().

doublereal& value ( size_t  i,
size_t  j 
)
inline

Returns a changeable reference to position in the matrix.

This is a key entry. Returns a reference to the matrixes (i,j) element. This may be used as an L value.

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

Definition at line 300 of file Array.h.

References Array2D::m_data, and Array2D::m_nrows.

Referenced by Array2D::appendColumn(), SquareMatrix::checkColumns(), SquareMatrix::checkRows(), DenseMatrix::leftMult(), Array2D::operator()(), and DebyeHuckel::s_update_lnMolalityActCoeff().

doublereal value ( size_t  i,
size_t  j 
) const
inline

Returns the value of a single matrix entry.

This is a key entry. Returns the value of the matrix position (i,j) element.

Parameters
iThe row index
jThe column index

Definition at line 312 of file Array.h.

References Array2D::m_data, and Array2D::m_nrows.

size_t nRows ( ) const
inline
size_t nColumns ( ) const
inline
iterator begin ( )
inline

Return an iterator pointing to the first element.

Definition at line 327 of file Array.h.

References Array2D::m_data.

Referenced by Array2D::axpy(), Cantera::operator*=(), and Cantera::operator+=().

iterator end ( )
inline

Return an iterator pointing past the last element.

Definition at line 332 of file Array.h.

References Array2D::m_data.

Referenced by Array2D::axpy(), Cantera::operator*=(), and Cantera::operator+=().

const_iterator begin ( ) const
inline

Return a const iterator pointing to the first element.

Definition at line 337 of file Array.h.

References Array2D::m_data.

const_iterator end ( ) const
inline

Return a const iterator pointing to past the last element.

Definition at line 342 of file Array.h.

References Array2D::m_data.

vector_fp& data ( )
inline

Return a reference to the data vector.

Definition at line 347 of file Array.h.

References Array2D::m_data.

const vector_fp& data ( ) const
inline

Return a const reference to the data vector.

Definition at line 352 of file Array.h.

References Array2D::m_data.

doublereal* ptrColumn ( size_t  j)
inline
const doublereal* ptrColumn ( size_t  j) const
inline

Return a const pointer to the top of column j, columns are contiguous in memory.

Parameters
jValue of the column
Returns
Returns a const pointer to the top of the column

Definition at line 374 of file Array.h.

References Array2D::m_data, and Array2D::m_nrows.

Member Data Documentation

vector_fp m_data
protected
size_t m_nrows
protected
size_t m_ncols
protected

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