MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
FastElim Class Reference
+ Inheritance diagram for FastElim:
+ Collaboration diagram for FastElim:

Public Member Functions

const double * allEntries () const
 
void buildBackwardSub (vector< unsigned int > &diag, vector< Triplet< double > > &bops, vector< double > &diagVal)
 
void buildForwardElim (vector< unsigned int > &diag, vector< Triplet< double > > &fops)
 
bool hinesReorder (const vector< unsigned int > &parentVoxel)
 
void makeTestMatrix (const double *test, unsigned int numCompts)
 
void shuffleRows (const vector< unsigned int > &lookupOldRowFromNew)
 
- Public Member Functions inherited from SparseMatrix< double >
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)
 

Additional Inherited Members

- Protected Attributes inherited from SparseMatrix< double >
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...
 

Detailed Description

Definition at line 40 of file standaloneTestFastElim.cpp.

Member Function Documentation

const double * FastElim::allEntries ( ) const

Definition at line 73 of file standaloneTestFastElim.cpp.

73  {
74  return &N_[0];
75 }
vector< double > N_
Definition: SparseMatrix.h:703
void FastElim::buildBackwardSub ( vector< unsigned int > &  diag,
vector< Triplet< double > > &  bops,
vector< double > &  diagVal 
)

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 352 of file standaloneTestFastElim.cpp.

Referenced by main().

354 {
355  // This vec tells the routine which rows below have to be back-subbed.
356  // This includes the rows if any in the tridiagonal band and also
357  // rows, if any, on branches.
358  vector< vector< unsigned int > > rowsToSub( nrows_ );
359 
360  for ( unsigned int i = 0; i < nrows_; ++i ) {
361  unsigned int d = diag[i] + 1;
362  unsigned int re = rowStart_[i+1];
363  for ( unsigned int j = d; j < re; ++j ) {
364  unsigned int k = colIndex_[j];
365  // At this point the row to sub is at (i, k). We need to go down
366  // to the (k,k) diagonal to sub it out.
367  rowsToSub[ k ].push_back( i );
368  }
369  }
370  for ( unsigned int i = 0; i < rowsToSub.size(); ++i ) {
371  cout << i << " : ";
372  for ( unsigned int j = 0; j < rowsToSub[i].size(); ++j ) {
373  cout << rowsToSub[i][j] << " ";
374  }
375  cout << endl;
376  }
377 
378  diagVal.resize( 0 );
379  // Fill in the diagonal terms. Here we do all entries.
380  for ( unsigned int i = 0; i != nrows_ ; ++i ) {
381  diagVal.push_back( 1.0 / N_[diag[i]] );
382  }
383 
384  // Fill in the back-sub operations. Note we don't need to check zero.
385  for ( unsigned int i = nrows_-1; i != 0 ; --i ) {
386  for ( unsigned int j = rowsToSub[i].size() - 1; j != -1; --j ) {
387  unsigned int k = rowsToSub[i][j];
388  double val = get( k, i ); //k is the row to go, i is the diag.
389  bops.push_back( Triplet< double >( val * diagVal[i], i, k ) );
390  }
391  }
392 
393  for ( unsigned int i = 0; i < bops.size(); ++i ) {
394  cout << i << ": " << bops[i].a_ << " " <<
395  bops[i].b_ << " " << // diagonal index
396  bops[i].c_ << " " << // off-diagonal index
397  1.0 / diagVal[bops[i].b_] << // diagonal value.
398  endl;
399  }
400 }
vector< double > N_
Definition: SparseMatrix.h:703
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 FastElim::buildForwardElim ( vector< unsigned int > &  diag,
vector< Triplet< double > > &  fops 
)

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 286 of file standaloneTestFastElim.cpp.

Referenced by main().

288 {
289  vector< vector< unsigned int > > rowsToElim( nrows_ );
290  diag.clear();
291  for ( unsigned int i = 0; i < nrows_; ++i ) {
292  unsigned int rs = rowStart_[i];
293  unsigned int re = rowStart_[i+1];
294  for ( unsigned int j = rs; j < re; ++j ) {
295  unsigned int k = colIndex_[j];
296  if ( k == i ) {
297  diag.push_back(j);
298  } else if ( k > i ) {
299  rowsToElim[ i ].push_back( k );
300  }
301  }
302  }
303  for ( unsigned int i = 0; i < nrows_; ++i ) {
304  double d = N_[diag[i]];
305  unsigned int diagend = rowStart_[ i + 1 ];
306  assert( diag[i] < diagend );
307  vector< unsigned int >& elim = rowsToElim[i];
308  for ( unsigned int j = 0; j < elim.size(); ++j ) {
309  unsigned int erow = elim[j];
310  if ( erow == i ) continue;
311  unsigned int rs = rowStart_[ erow ];
312  unsigned int re = rowStart_[ erow+1 ];
313  // assert( colIndex_[rs] == i );
314  double ratio = get( erow, i ) / d;
315  // double ratio = N_[rs]/N_[diag[i]];
316  for ( unsigned int k = diag[i]+1; k < diagend; ++k ) {
317  unsigned int col = colIndex_[k];
318  // findElimEntry, subtract it out.
319  for ( unsigned int q = rs; q < re; ++q ) {
320  if ( colIndex_[q] == col ) {
321  N_[q] -= N_[k] * ratio;
322  }
323  }
324  }
325  fops.push_back( Triplet< double >( ratio, i, erow) );
326  }
327  }
328  for ( unsigned int i = 0; i < rowsToElim.size(); ++i ) {
329  cout << i << " : ";
330  for ( unsigned int j = 0; j < rowsToElim[i].size(); ++j ) {
331  cout << rowsToElim[i][j] << " ";
332  }
333  cout << endl;
334  }
335  for ( unsigned int i = 0; i < fops.size(); ++i ) {
336  cout << "fops[" << i << "]= " << fops[i].b_ << " " << fops[i].c_ <<
337  " " << fops[i].a_ << endl;
338  }
339  /*
340  */
341 }
vector< double > N_
Definition: SparseMatrix.h:703
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:

bool FastElim::hinesReorder ( const vector< unsigned int > &  parentVoxel)

Reorders rows and columns to put the matrix in the form suitable for rapid single-pass inversion. Returns 0 on failure.

Definition at line 85 of file standaloneTestFastElim.cpp.

Referenced by main().

86 {
87  // First we fill in the vector that specifies the old row number
88  // assigned to each row of the reordered matrix.
89  assert( parentVoxel.size() == nrows_ );
90  vector< unsigned int > numKids( nrows_, 0 );
91  vector< unsigned int > lookupOldRowFromNew;
92  vector< bool > rowPending( nrows_, true );
93  unsigned int numDone = 0;
94  for ( unsigned int i = 0; i < nrows_; ++i ) {
95  if ( parentVoxel[i] != -1 )
96  numKids[ parentVoxel[i] ]++;
97  }
98  while ( numDone < nrows_ ) {
99  for ( unsigned int i = 0; i < nrows_; ++i ) {
100  if ( rowPending[i] && numKids[i] == 0 ) {
101  lookupOldRowFromNew.push_back( i );
102  rowPending[i] = false;
103  numDone++;
104  unsigned int pa = parentVoxel[i];
105  // Unsure what the root parent is. Assume it is -1
106  while ( pa != -1 && numKids[pa] == 1 ) {
107  assert( rowPending[pa] );
108  rowPending[pa] = false;
109  numDone++;
110  lookupOldRowFromNew.push_back( pa );
111  pa = parentVoxel[pa];
112  }
113  if ( pa != -1 ) {
114  assert( numKids[pa] > 0 );
115  numKids[pa]--;
116  }
117  }
118  }
119  }
120 
121  cout << setprecision(4);
122  cout << "oldRowFromNew= {" ;
123  for ( int i = 0; i < nrows_; ++i )
124  cout << lookupOldRowFromNew[i] << ", ";
125  cout << "}\n";
126  // Then we fill in the reordered matrix. Note we need to reorder
127  // columns too.
128  shuffleRows( lookupOldRowFromNew );
129 }
void shuffleRows(const vector< unsigned int > &lookupOldRowFromNew)

+ Here is the caller graph for this function:

void FastElim::makeTestMatrix ( const double *  test,
unsigned int  numCompts 
)

Finds the 'twigs' of the matrix: Only one end connected. void FastElim::extractTwig( unsigned int i, vector< unsigned int >& rowReorder, vector< bool >& extracted ) { ; }

void FastElim::findClosedEnds( vector< unsigned int >& rowReorder, vector< bool >& extracted ) { ; }

void FastElim::extractClosedEnds( unsigned int i, vector< unsigned int >& rowReorder, vector< bool >& extracted ) { ; }

Definition at line 255 of file standaloneTestFastElim.cpp.

Referenced by main().

256 {
257  setSize( numCompts, numCompts );
258  vector< double > row( numCompts, ~0 );
259  unsigned int i = 1;
260  for ( unsigned int i = 0; i < numCompts; ++i ) {
261  for ( unsigned int j = 0; j < numCompts; ++j ) {
262  unsigned int k = i * numCompts + j;
263  if ( test[k] < 0.1 ) {
264  } else {
265  N_.push_back( test[k] );
266  colIndex_.push_back( j );
267  }
268  }
269  rowStart_[i + 1] = N_.size();
270  }
271 }
vector< double > N_
Definition: SparseMatrix.h:703
void setSize(unsigned int nrows, unsigned int ncolumns)
Definition: SparseMatrix.h:126
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 FastElim::shuffleRows ( const vector< unsigned int > &  lookupOldRowFromNew)

Definition at line 132 of file standaloneTestFastElim.cpp.

References SparseMatrix< T >::getRow(), SparseMatrix< T >::nrows_, and sortByColumn().

134 {
135  vector< unsigned int > lookupNewRowFromOld( nrows_ );
136  for ( unsigned int i = 0; i < nrows_; ++i )
137  lookupNewRowFromOld[ lookupOldRowFromNew[i] ] = i;
138 
139  FastElim temp = *this;
140  clear();
141  setSize( temp.nrows_, temp.nrows_ );
142  for ( unsigned int i = 0; i < lookupOldRowFromNew.size(); ++i ) {
143  vector< unsigned int > c;
144  vector< double > e;
145  unsigned int num = temp.getRow( lookupOldRowFromNew[i], e, c );
146  vector< unsigned int > newc( num );
147  vector< double > newe( num );
148  for ( unsigned int j = 0; j < num; ++j ) {
149  newc[j] = lookupNewRowFromOld[ c[j] ];
150  newe[j] = e[j];
151  }
152  // Now we need to sort the new row entries in increasing col order.
153  /*
154  sortByColumn( newc, newe );
155  addRow( i, newe, newc );
156  */
157  sortByColumn( newc, e );
158  addRow( i, e, newc );
159  }
160 }
unsigned int getRow(unsigned int row, const T **entry, const unsigned int **colIndex) const
Definition: SparseMatrix.h:288
void addRow(unsigned int rowNum, const vector< double > &row)
Definition: SparseMatrix.h:387
void sortByColumn(vector< unsigned int > &col, vector< double > &entry)
void setSize(unsigned int nrows, unsigned int ncolumns)
Definition: SparseMatrix.h:126

+ Here is the call graph for this function:


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