Array2D Class Reference

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

#include <Array.h>

List of all members.

Public Types

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

Public Member Functions

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

Protected Attributes

vector_fp m_data
 Data storred in a single array.
int m_nrows
 Number of rows.
int m_ncols
 Number of columns.

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


Member Typedef Documentation

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

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


Constructor & Destructor Documentation

Array2D (  )  [inline]

Default constructor.

Create an empty array.

Definition at line 43 of file Array.h.

Array2D ( const int  m,
const int  n,
const doublereal  v = 0.0 
) [inline]

Constructor.

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

Parameters:
m Number of rows
n Number of columns
v Default fill value. The default is 0.0

Definition at line 56 of file Array.h.

References Array2D::m_data.

Array2D ( const Array2D y  )  [inline]

Copy constructor.

Parameters:
y Array2D to make the copy from

Definition at line 66 of file Array.h.

References Array2D::m_data.

virtual ~Array2D (  )  [inline, virtual]

Destructor.

Does nothing, since no memory allocated on the heap.

Definition at line 182 of file Array.h.

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


Member Function Documentation

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:
c This 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 121 of file Array.h.

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

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:
c This 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 106 of file Array.h.

References Array2D::m_data, Array2D::m_ncols, 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:
a scalar to multiply x with
x First Array2D object to be used
y Second Array2D object to be used

Definition at line 196 of file Array.h.

const_iterator begin (  )  const [inline]

Return a const iterator pointing to the first element.

Definition at line 264 of file Array.h.

iterator begin (  )  [inline]

Return an iterator pointing to the first element.

Definition at line 258 of file Array.h.

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

const vector_fp& data (  )  const [inline]

Return a const reference to the data vector.

Definition at line 273 of file Array.h.

References Array2D::m_data.

vector_fp& data (  )  [inline]

Return a reference to the data vector.

Definition at line 270 of file Array.h.

References Array2D::m_ncols.

const_iterator end (  )  const [inline]

Return a const iterator pointing to past the last element.

Definition at line 267 of file Array.h.

References Array2D::m_nrows.

iterator end (  )  [inline]

Return an iterator pointing past the last element.

Definition at line 261 of file Array.h.

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

void getColumn ( int  m,
doublereal *const   col 
) [inline]

Get the values in column m.

col(i) = A(i,m)

Parameters:
m Column to set
col pointer to a col vector that will be returned

Definition at line 172 of file Array.h.

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

void getRow ( int  n,
doublereal *const   rw 
) [inline]

Get the nth row and return it in a vector.

Parameters:
n Index of the row to be returned.
rw Return Vector for the operation. Must have a length of m_ncols.

Definition at line 145 of file Array.h.

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

size_t nColumns (  )  const [inline]

Number of columns.

Definition at line 255 of file Array.h.

Referenced by Cantera::operator<<().

size_t nRows (  )  const [inline]

Number of rows.

Definition at line 252 of file Array.h.

Referenced by Cantera::operator<<().

doublereal operator() ( int  i,
int  j 
) const [inline]

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

Parameters:
i Index for the row to be retrieved
j Index for the column to be retrieved.
Returns:
Returns the value of the matrix entry

Definition at line 221 of file Array.h.

References Array2D::value().

doublereal& operator() ( int  i,
int  j 
) [inline]

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

Parameters:
i row index
j column index.
Returns:
Returns a reference to A(i,j) which may be assigned.

Definition at line 211 of file Array.h.

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

Array2D& operator= ( const Array2D y  )  [inline]

assignment operator

Parameters:
y Array2D to get the values from

Definition at line 77 of file Array.h.

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

const doublereal* ptrColumn ( int  j  )  const [inline]

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

Parameters:
j Value of the column
Returns:
Returns a const pointer to the top of the column

Definition at line 291 of file Array.h.

doublereal* ptrColumn ( int  j  )  [inline]

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

Parameters:
j Value of the column
Returns:
Returns a pointer to the top of the column

Definition at line 282 of file Array.h.

References Array2D::m_data.

Referenced by HMWSoln::s_updatePitzer_CoeffWRTemp().

void resize ( int  n,
int  m,
doublereal  v = 0.0 
) [inline]

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

Parameters:
n This is the number of rows
m This is the number of columns in the new matrix
v Default fill value -> defaults to zero.

Definition at line 92 of file Array.h.

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

Referenced by HMWSoln::initLengths(), DebyeHuckel::initLengths(), and HMWSoln::readXMLLambdaNeutral().

void setColumn ( int  m,
doublereal *const   col 
) [inline]

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

A(i,m) = col(i)

Parameters:
m Column to set
col pointer to a col vector. Vector must have a length of m_nrows.

Definition at line 159 of file Array.h.

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

void setRow ( int  n,
const doublereal *const   rw 
) [inline]

Set the nth row to array rw.

Parameters:
n Index of the row to be changed
rw Vector for the row. Must have a length of m_ncols.

Definition at line 133 of file Array.h.

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

doublereal value ( int  i,
int  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:
i The row index
j The column index

Definition at line 247 of file Array.h.

doublereal& value ( int  i,
int  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:
i The row index
j The column index
Returns:
Returns a changeable reference to the matrix entry

Definition at line 235 of file Array.h.

Referenced by Array2D::appendColumn(), Array2D::operator()(), DebyeHuckel::s_update_lnMolalityActCoeff(), and Array2D::setRow().


Member Data Documentation

vector_fp m_data [protected]
int m_ncols [protected]
int m_nrows [protected]

The documentation for this class was generated from the following file:
Generated by  doxygen 1.6.3