MOOSE - Multiscale Object Oriented Simulation Environment
|
#include <FastMatrixElim.h>
Public Member Functions | |
void | buildBackwardSub (vector< unsigned int > &diag, vector< Triplet< double > > &bops, vector< double > &diagVal) |
bool | buildForDiffusion (const vector< unsigned int > &parentVoxel, const vector< double > &volume, const vector< double > &area, const vector< double > &length, double diffConst, double motorConst, double dt) |
This function makes the diffusion matrix. More... | |
void | buildForwardElim (vector< unsigned int > &diag, vector< Triplet< double > > &fops) |
bool | checkSymmetricShape () const |
FastMatrixElim () | |
FastMatrixElim (unsigned int nrows, unsigned int ncolumns) | |
FastMatrixElim (const SparseMatrix< double > &orig) | |
bool | hinesReorder (const vector< unsigned int > &parentVoxel, vector< unsigned int > &lookupOldRowsFromNew) |
bool | isSymmetric () const |
void | makeTestMatrix (const double *test, unsigned int numCompts) |
bool | operator== (const FastMatrixElim &other) const |
void | setDiffusionAndTransport (const vector< unsigned int > &parentVoxel, double diffConst, double motorConst, double dt) |
void | shuffleRows (const vector< unsigned int > &lookupOldRowFromNew) |
![]() | |
void | addRow (unsigned int rowNum, const vector< double > &row) |
void | addRow (unsigned int rowNum, const vector< double > &entry, const vector< unsigned int > &colIndexArg) |
void | clear () |
const vector< unsigned int > & | colIndex () const |
double | get (unsigned int row, unsigned int column) const |
unsigned int | getColumn (unsigned int col, vector< double > &entry, vector< unsigned int > &rowIndex) const |
unsigned int | getRow (unsigned int row, const double **entry, const unsigned int **colIndex) const |
unsigned int | getRow (unsigned int row, vector< double > &e, vector< unsigned int > &c) const |
const vector< double > & | 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, doublevalue) |
void | print () const |
void | printInternal () const |
void | printTriplet (const vector< Triplet< double > > &t) |
void | reorderColumns (const vector< unsigned int > &colMap) |
const vector< unsigned int > & | rowStart () const |
void | set (unsigned int row, unsigned int column, doublevalue) |
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< double > &z, bool retainSize=false) |
void | unset (unsigned int row, unsigned int column) |
Static Public Member Functions | |
static void | advance (vector< double > &y, const vector< Triplet< double > > &ops, const vector< double > &diagVal) |
static void | opsReorder (const vector< unsigned int > &lookupOldRowsFromNew, vector< Triplet< double > > &ops, vector< double > &diagVal) |
Additional Inherited Members | |
![]() | |
vector< unsigned int > | colIndex_ |
Non-zero entries in the SparseMatrix. More... | |
vector< double > | N_ |
unsigned int | ncolumns_ |
unsigned int | nrows_ |
vector< unsigned int > | rowStart_ |
Start index in the N_ and colIndex_ vectors, of each row. More... | |
Definition at line 10 of file FastMatrixElim.h.
FastMatrixElim::FastMatrixElim | ( | ) |
Definition at line 29 of file FastMatrixElim.cpp.
FastMatrixElim::FastMatrixElim | ( | unsigned int | nrows, |
unsigned int | ncolumns | ||
) |
Definition at line 33 of file FastMatrixElim.cpp.
FastMatrixElim::FastMatrixElim | ( | const SparseMatrix< double > & | orig | ) |
Definition at line 37 of file FastMatrixElim.cpp.
|
static |
Does the actual computation of the matrix inversion, which is equivalent to advancing one timestem in Backward Euler. Static function here to keep namespaces clean.
Definition at line 472 of file FastMatrixElim.cpp.
Referenced by testFastMatrixElim().
void FastMatrixElim::buildBackwardSub | ( | vector< unsigned int > & | diag, |
vector< Triplet< double > > & | bops, | ||
vector< double > & | diagVal | ||
) |
Reduces the backward substitution phase into a series of operations defined by the bops vector, and by the list of values on the diagonal.
Operations to be done on the RHS for the back sub are generated and put into the bops (backward ops) vector. col > row here, row is the entry being operated on, and col is given by rowsToSub. offDiagVal is the value on the off-diagonal at row,col. diagVal is the value on the diagonal at [row][row]. RHS[row] = ( RHS[row] - offDiagVal * RHS[col] ) / diagVal
Definition at line 342 of file FastMatrixElim.cpp.
References SparseMatrix< double >::colIndex_, SparseMatrix< double >::N_, SparseMatrix< double >::nrows_, and SparseMatrix< double >::rowStart_.
Referenced by Dsolve::build(), and testFastMatrixElim().
bool FastMatrixElim::buildForDiffusion | ( | const vector< unsigned int > & | parentVoxel, |
const vector< double > & | volume, | ||
const vector< double > & | area, | ||
const vector< double > & | length, | ||
double | diffConst, | ||
double | motorConst, | ||
double | dt | ||
) |
This function makes the diffusion matrix.
This function makes the matrix for computing diffusion and transport equations.
Definition at line 557 of file FastMatrixElim.cpp.
References SparseMatrix< double >::addRow(), buildColIndex(), SparseMatrix< double >::colIndex(), EMPTY_VOXEL(), findAreaProportion(), and SparseMatrix< double >::nrows_.
Referenced by Dsolve::build().
void FastMatrixElim::buildForwardElim | ( | vector< unsigned int > & | diag, |
vector< Triplet< double > > & | fops | ||
) |
Recursively scans the current matrix, to build tree of parent voxels using the contents of the sparase matrix to indicate connectivity. Emits warning noises and returns an empty vector if the entire tree cannot be traversed, or if the current matrix is not tree-like. Assumes row 0 is root row. User should always call with parentRow == 0; Doesn't work yet. bool buildTree( unsigned int parentRow, vector< unsigned int >& parentVoxel ) const; Reduces the forward elimination phase into a series of operations defined by the fops vector.
Builds the vector of forward ops: ratio, i, j RHS[i] = RHS[i] - RHS[j] * ratio This vec tells the routine which rows below have to be eliminated. This includes the rows if any in the tridiagonal band and also rows, if any, on branches.
Definition at line 275 of file FastMatrixElim.cpp.
References SparseMatrix< double >::colIndex_, SparseMatrix< double >::N_, SparseMatrix< double >::nrows_, and SparseMatrix< double >::rowStart_.
Referenced by Dsolve::build(), and testFastMatrixElim().
bool FastMatrixElim::checkSymmetricShape | ( | ) | const |
Checks that the matrix shape (but not necessarily values) are symmetric, returns true if symmetric.
Definition at line 51 of file FastMatrixElim.cpp.
References SparseMatrix< double >::colIndex_, SparseMatrix< T >::colIndex_, SparseMatrix< double >::N_, SparseMatrix< T >::N_, SparseMatrix< T >::ncolumns_, SparseMatrix< double >::ncolumns_, SparseMatrix< double >::nrows_, SparseMatrix< T >::nrows_, SparseMatrix< double >::rowStart_, SparseMatrix< T >::rowStart_, and SparseMatrix< T >::transpose().
Referenced by Dsolve::build().
bool FastMatrixElim::hinesReorder | ( | const vector< unsigned int > & | parentVoxel, |
vector< unsigned int > & | lookupOldRowFromNew | ||
) |
Takes the tree specification in the form of a list of parent entries for each tree node, and reorders the matrix into the twig-first sequence required for fast elimination. Returns true if it succeeded in doing this; many matrices will not reorder correctly.
Scans the current matrix starting from index 0, to build tree of parent voxels using the contents of the sparase matrix to indicate connectivity. Emits warning noises and returns an empty vector if the entire tree cannot be traversed, or if the current matrix is not tree-like. This still doesn't work. Fails because it cannot detect branches in the tree, where sibling compartments would have cross talk. So we still rely on getParentVoxel function. bool FastMatrixElim::buildTree( unsigned int parentRow, vector< unsigned int >& parentVoxel ) const { assert( nRows() == nColumns() ); if ( parentRow == 0 ) { parentVoxel.assign( nRows, EMPTY_VOXEL ); if ( !checkSymmetricShape() ) return false; // shape of matrix should be symmetric. } const double* entry; const unsigned int* colIndex; unsigned int numEntries = getRow( parentRow, &entry, &colIndex ); for ( unsigned int j = 0; j < numEntries; ++j ) { if ( colIndex[j] <= parentRow ) continue; // ignore lower diagonal if ( parentVoxel[ colIndex[j] ] == EMPTY_VOXEL ) { parentVoxel[ colIndex[j] ] = parentRow; } else { if ( parentVoxel[ colIndex[j] ] == parentVoxel[ parentRow ] ) continue; // OK, these are sibling compartments return false; // Error: the matrix isn't a clean tree. } } for ( unsigned int j = 0; j < numEntries; ++j ) { if ( colIndex[j] <= parentRow ) continue; if !buildTree( colIndex[j], parentVoxel ) return false; // Propagate error from child row. } if ( parentRow > 0 ) return true; Now done with all child branches, test if whole matrix is in tree. for ( unsigned int j = 1; j < nRows(); ++j ) if ( parentVoxel[j] == EMPTY_VOXEL ) return false; // One or more rows is disconnected from tree
return true; // All is well, have yourself a nice parentVoxel tree. } Reorders rows and columns to put the matrix in the form suitable for rapid single-pass inversion. Returns 0 on failure, but at this point I don't have a proper test for this.
Definition at line 139 of file FastMatrixElim.cpp.
References EMPTY_VOXEL(), SparseMatrix< double >::nrows_, and shuffleRows().
Referenced by Dsolve::build(), and testFastMatrixElim().
bool FastMatrixElim::isSymmetric | ( | ) | const |
Definition at line 80 of file FastMatrixElim.cpp.
References SparseMatrix< T >::transpose().
void FastMatrixElim::makeTestMatrix | ( | const double * | test, |
unsigned int | numCompts | ||
) |
Definition at line 244 of file FastMatrixElim.cpp.
References SparseMatrix< double >::colIndex_, SparseMatrix< double >::N_, SparseMatrix< double >::rowStart_, and SparseMatrix< double >::setSize().
Referenced by testFastMatrixElim(), and testSetDiffusionAndTransport().
bool FastMatrixElim::operator== | ( | const FastMatrixElim & | other | ) | const |
Definition at line 64 of file FastMatrixElim.cpp.
References SparseMatrix< double >::colIndex_, SparseMatrix< T >::colIndex_, doubleEq(), SparseMatrix< double >::N_, SparseMatrix< T >::N_, SparseMatrix< double >::ncolumns_, SparseMatrix< T >::ncolumns_, SparseMatrix< T >::nrows_, SparseMatrix< double >::nrows_, SparseMatrix< T >::rowStart_, and SparseMatrix< double >::rowStart_.
|
static |
static function. Reorders the ops and diagVal vectors so as to restore the original indexing of the input vectors.
Definition at line 491 of file FastMatrixElim.cpp.
Referenced by Dsolve::build().
void FastMatrixElim::setDiffusionAndTransport | ( | const vector< unsigned int > & | parentVoxel, |
double | diffConst, | ||
double | motorConst, | ||
double | dt | ||
) |
This function incorporates molecule-specific diffusion and motor transport terms into the matrix.
Put in diff and transport terms and also fill in the diagonal The terms are: n-1: dt*(D+M)*adx(-) n: 1 -dt*[ D*adx(-) +D*adx(+) + M*adx(+) ] n+1: dt*D*adx(+) Note that there will be only one parent term but possibly many distal terms.
Definition at line 405 of file FastMatrixElim.cpp.
References SparseMatrix< double >::colIndex_, SparseMatrix< T >::colIndex_, EMPTY_VOXEL(), SparseMatrix< double >::N_, SparseMatrix< T >::N_, SparseMatrix< T >::ncolumns_, SparseMatrix< T >::nrows_, SparseMatrix< double >::nrows_, SparseMatrix< double >::rowStart_, and SparseMatrix< T >::rowStart_.
Referenced by testSetDiffusionAndTransport().
void FastMatrixElim::shuffleRows | ( | const vector< unsigned int > & | lookupOldRowFromNew | ) |
Reorders rows of the matrix according to the vector lookupOldRowFromNew. The vector tells the function which old row to put in the ith row of the new matrix. Since the matrix has matching column entries, those get shuffled too.
Definition at line 193 of file FastMatrixElim.cpp.
References SparseMatrix< double >::addRow(), SparseMatrix< double >::clear(), SparseMatrix< T >::getRow(), SparseMatrix< double >::nrows_, SparseMatrix< T >::nrows_, SparseMatrix< double >::setSize(), and sortByColumn().
Referenced by hinesReorder().