MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
KinSparseMatrix Class Reference

#include <KinSparseMatrix.h>

+ Inheritance diagram for KinSparseMatrix:
+ Collaboration diagram for KinSparseMatrix:

Public Member Functions

double computeRowRate (unsigned int row, const vector< double > &v) const
 
void fireReac (unsigned int reacIndex, vector< double > &S, double direction) const
 
void getGillespieDependence (unsigned int row, vector< unsigned int > &cols) const
 
void truncateRow (unsigned int maxColumnIndex)
 
- Public Member Functions inherited from SparseMatrix< int >
void addRow (unsigned int rowNum, const vector< int > &row)
 
void addRow (unsigned int rowNum, const vector< int > &entry, const vector< unsigned int > &colIndexArg)
 
void clear ()
 
const vector< unsigned int > & colIndex () const
 
int get (unsigned int row, unsigned int column) const
 
unsigned int getColumn (unsigned int col, vector< int > &entry, vector< unsigned int > &rowIndex) const
 
unsigned int getRow (unsigned int row, const int **entry, const unsigned int **colIndex) const
 
unsigned int getRow (unsigned int row, vector< int > &e, vector< unsigned int > &c) const
 
const vector< int > & matrixEntry () const
 Here we expose the sparse matrix for MOOSE use. More...
 
unsigned int nColumns () const
 
unsigned int nEntries () const
 
unsigned int nRows () const
 
void pairFill (const vector< unsigned int > &row, const vector< unsigned int > &col, intvalue)
 
void print () const
 
void printInternal () const
 
void printTriplet (const vector< Triplet< int > > &t)
 
void reorderColumns (const vector< unsigned int > &colMap)
 
const vector< unsigned int > & rowStart () const
 
void set (unsigned int row, unsigned int column, intvalue)
 
void setSize (unsigned int nrows, unsigned int ncolumns)
 
 SparseMatrix ()
 
 SparseMatrix (unsigned int nrows, unsigned int ncolumns)
 
void transpose ()
 
void tripletFill (const vector< unsigned int > &row, const vector< unsigned int > &col, const vector< int > &z, bool retainSize=false)
 
void unset (unsigned int row, unsigned int column)
 

Private Attributes

vector< unsigned int > rowTruncated_
 

Additional Inherited Members

- Protected Attributes inherited from SparseMatrix< int >
vector< unsigned int > colIndex_
 Non-zero entries in the SparseMatrix. More...
 
vector< int > N_
 
unsigned int ncolumns_
 
unsigned int nrows_
 
vector< unsigned int > rowStart_
 Start index in the N_ and colIndex_ vectors, of each row. More...
 

Detailed Description

Definition at line 13 of file KinSparseMatrix.h.

Member Function Documentation

double KinSparseMatrix::computeRowRate ( unsigned int  row,
const vector< double > &  v 
) const

Returns all non-zero column indices, for the specified row. This gives reac #s in orig matrix, and molecule #s in the transposed matrix Not needed. The getRow function does all this, more efficiently. int getRowIndices( unsigned int row, vector< unsigned int >& indices ); Returns the dot product of the specified row with the vector v. v corresponds to the vector of reaction rates. v must have nColumns entries.

Returns the dot product of the specified row with the vector v. v corresponds to the vector of reaction rates. v must have nColumns entries.

Definition at line 28 of file KinSparseMatrix.cpp.

References numEntries.

Referenced by VoxelPools::updateRates().

31 {
32  assert( nColumns() == 0 || row < nRows() );
33  assert( v.size() == nColumns() );
34  const int* entry = 0;
35  const unsigned int* colIndex = 0;
36  unsigned int numEntries = getRow( row, &entry, &colIndex );
37  const int* end = entry + numEntries;
38 
39  double ret = 0.0;
40  for ( const int* i = entry; i != end; ++i ) {
41  ret += *i * v[ *colIndex++ ];
42  }
43 
44 /*
45  for ( unsigned int i = 0; i < numEntries; ++i ) {
46  ret += entry[i] * v[ colIndex[i] ];
47 
48  }
49 
50  vector< int >::const_iterator i;
51  unsigned int rs = rowStart_[ row ];
52  vector< unsigned int >::const_iterator j = colIndex_.begin() + rs;
53  vector< int >::const_iterator end = N_.begin() + rowStart_[ row + 1 ];
54 
55  double ret = 0.0;
56  for ( i = N_.begin() + rs; i != end; i++ )
57  ret += *i * v[ *j++ ];
58 
59  // assert ( !( ret !<>= 0.0 ) );
60  */
61 
62  assert ( !( std::isnan( ret ) ) );
63  return ret;
64 }
unsigned int nColumns() const
Definition: SparseMatrix.h:92
unsigned int getRow(unsigned int row, const int **entry, const unsigned int **colIndex) const
Definition: SparseMatrix.h:288
unsigned int nRows() const
Definition: SparseMatrix.h:87
const int numEntries
Definition: proc.cpp:60
const vector< unsigned int > & colIndex() const
Definition: SparseMatrix.h:431

+ Here is the caller graph for this function:

void KinSparseMatrix::fireReac ( unsigned int  reacIndex,
vector< double > &  S,
double  direction 
) const

Fires a stochastic reaction: It undergoes a single transition This operation updates the mol concs due to the reacn. Direction is +1 or -1, specifies direction of reaction

This too operates on the transposed matrix, because we need to get all the molecules for a given reac: a column in the original N matrix. Direction [-1,+1] specifies whether the reaction is forward or backward.

Definition at line 113 of file KinSparseMatrix.cpp.

Referenced by GssaVoxelPools::advance().

115 {
116  assert( ncolumns_ == S.size() && reacIndex < nrows_ );
117  unsigned int rowBeginIndex = rowStart_[ reacIndex ];
118  // vector< int >::const_iterator rowEnd = N_.begin() + rowStart_[ reacIndex + 1];
119  vector< int >::const_iterator rowBegin =
120  N_.begin() + rowBeginIndex;
121  vector< int >::const_iterator rowEnd =
122  N_.begin() + rowTruncated_[ reacIndex ];
123  vector< unsigned int >::const_iterator molIndex =
124  colIndex_.begin() + rowBeginIndex;
125 
126  for ( vector< int >::const_iterator i = rowBegin; i != rowEnd; ++i ) {
127  double& x = S[ *molIndex++ ];
128  x += *i * direction;
129  x *= (x > 0 );
130  // assert( S[ *molIndex ] + *i * direction >= 0.0 );
131  // S[ *molIndex++ ] += *i * direction;
132  }
133 }
unsigned int ncolumns_
Definition: SparseMatrix.h:702
vector< unsigned int > rowTruncated_
vector< int > N_
Definition: SparseMatrix.h:703
unsigned int nrows_
Definition: SparseMatrix.h:701
vector< unsigned int > colIndex_
Non-zero entries in the SparseMatrix.
Definition: SparseMatrix.h:709
vector< unsigned int > rowStart_
Start index in the N_ and colIndex_ vectors, of each row.
Definition: SparseMatrix.h:712

+ Here is the caller graph for this function:

void KinSparseMatrix::getGillespieDependence ( unsigned int  row,
vector< unsigned int > &  deps 
) const

Does a special self-product of the specified row. Output is the set of nonzero indices in the product abs( Rij ) * neg( Rjk ) for the specified index i, where neg( val ) is true only if val < 0.

Has to operate on transposed matrix row argument refers to reac# in this transformed situation. Fills up 'deps' with reac::s that depend on the row argument. Does NOT ensure that list is unique.

Definition at line 73 of file KinSparseMatrix.cpp.

Referenced by Gsolve::rebuildGssaSystem().

76 {
77  deps.resize( 0 );
78  // vector< unsigned int > deps;
79  for ( unsigned int i = 0; i < nrows_; ++i ) {
80  // i is index for reac # here. Note that matrix is transposed.
81  unsigned int j = rowStart_[ row ];
82  unsigned int jend = rowStart_[ row + 1 ];
83  unsigned int k = rowStart_[ i ];
84  unsigned int kend = rowStart_[ i + 1 ];
85 
86  while ( j < jend && k < kend ) {
87  if ( colIndex_[ j ] == colIndex_[ k ] ) {
88  /* Pre 28 Nov 2015. Why below zero? Shouldn't it be any?
89  if ( N_[ k ] < 0 ) {
90  deps.push_back( i );
91  }
92  */
93  assert( round( N_[k] ) != 0 );
94  deps.push_back( i );
95  ++j;
96  ++k;
97  } else if ( colIndex_[ j ] < colIndex_[ k ] ) {
98  ++j;
99  } else if ( colIndex_[ j ] > colIndex_[ k ] ) {
100  ++k;
101  } else {
102  assert( 0 );
103  }
104  }
105  }
106 }
vector< int > N_
Definition: SparseMatrix.h:703
unsigned int nrows_
Definition: SparseMatrix.h:701
vector< unsigned int > colIndex_
Non-zero entries in the SparseMatrix.
Definition: SparseMatrix.h:709
vector< unsigned int > rowStart_
Start index in the N_ and colIndex_ vectors, of each row.
Definition: SparseMatrix.h:712

+ Here is the caller graph for this function:

void KinSparseMatrix::truncateRow ( unsigned int  maxColumnIndex)

This function generates a new internal list of rowEnds, such that they are all less than the maxColumnIndex. It is used because in fireReac we don't want to update all the molecules, only those that are variable.

Definition at line 141 of file KinSparseMatrix.cpp.

Referenced by Gsolve::rebuildGssaSystem().

142 {
143  rowTruncated_.resize( nrows_, 0 );
144  if ( colIndex_.size() == 0 )
145  return;
146  for ( unsigned int i = 0; i < nrows_; ++i ) {
147  unsigned int endCol = rowStart_[ i ];
148  for ( unsigned int j = rowStart_[ i ];
149  j < rowStart_[ i + 1 ]; ++j ) {
150  if ( colIndex_[ j ] < maxColumnIndex ) {
151  endCol = j + 1;
152  } else {
153  break;
154  }
155  }
156  rowTruncated_[ i ] = endCol;
157  }
158 }
vector< unsigned int > rowTruncated_
unsigned int nrows_
Definition: SparseMatrix.h:701
vector< unsigned int > colIndex_
Non-zero entries in the SparseMatrix.
Definition: SparseMatrix.h:709
vector< unsigned int > rowStart_
Start index in the N_ and colIndex_ vectors, of each row.
Definition: SparseMatrix.h:712

+ Here is the caller graph for this function:

Member Data Documentation

vector< unsigned int > KinSparseMatrix::rowTruncated_
private

End colIndex for rows (molecules in the transposed matrix) so that only variable molecules are below the colIndex.

Definition at line 69 of file KinSparseMatrix.h.


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