MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
MeshCompt.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 ** This program is part of 'MOOSE', the
3 ** Messaging Object Oriented Simulation Environment.
4 ** Copyright (C) 2011 Upinder S. Bhalla. and NCBS
5 ** It is made available under the terms of the
6 ** GNU Lesser General Public License version 2.1
7 ** See the file COPYING.LIB for the full notice.
8 **********************************************************************/
9 
10 #include "header.h"
11 #include "SparseMatrix.h"
12 #include "VoxelJunction.h"
13 #include "Boundary.h"
14 // #include "Stencil.h"
15 #include "MeshEntry.h"
16 #include "ChemCompt.h"
17 #include "MeshCompt.h"
18 
19 static const unsigned int EMPTY = ~0;
20 
22 // Class stuff.
25 {
26  ;
27 }
28 
30 {
31  ;
32 }
33 
35 // for diffusively coupled voxels from other solvers.
36 double MeshCompt::extendedMeshEntryVolume( unsigned int index ) const
37 {
38  assert( index < extendedMeshEntryVolume_.size() );
39  return extendedMeshEntryVolume_[ index ];
40 }
41 
44 {
46 }
47 
50 {
51  m_ = coreStencil_;
52 }
53 
54 unsigned int MeshCompt::getStencilRow( unsigned int meshIndex,
55  const double** entry, const unsigned int** colIndex ) const
56 {
57  return m_.getRow( meshIndex, entry, colIndex );
58 }
59 
61 {
62  return coreStencil_;
63 }
64 
65 
67 
69 vector< unsigned int > MeshCompt::getNeighbors( unsigned int row ) const
70 {
71  const double* entry;
72  const unsigned int *colIndex;
73 
74  unsigned int n = m_.getRow( row, &entry, &colIndex );
75 
76  vector< unsigned int > ret;
77  ret.insert( ret.end(), colIndex, colIndex + n );
78 
79  return ret;
80 }
81 
83 // Inherited virtual funcs for field access
85 vector< double > MeshCompt::innerGetStencilRate( unsigned int row ) const
86 {
87  const double* entry;
88  const unsigned int *colIndex;
89 
90  unsigned int n = m_.getRow( row, &entry, &colIndex );
91 
92  vector< double > ret;
93  ret.insert( ret.end(), entry, entry + n );
94 
95  return ret;
96 }
97 
98 void MeshCompt::addRow( unsigned int index,
99  const vector< double >& entry,
100  const vector< unsigned int >& colIndex
101  )
102 {
103  coreStencil_.addRow( index, entry, colIndex );
104 }
105 
106 void MeshCompt::setStencilSize( unsigned int numRows, unsigned int numCols )
107 {
109  coreStencil_.setSize( numRows, numCols );
110 }
111 
112 
122  const ChemCompt* other, const vector< VoxelJunction >& vj )
123 {
124  // Maps from remote meshIndex (in vj) to local index of proxy voxel.
125  map< unsigned int, unsigned int > meshMap;
126  map< unsigned int, unsigned int >::iterator mmi;
127 
128  // Maps from local index of proxy voxel back to remote meshIndex.
129  vector< unsigned int > meshBackMap;
130 
131 
132  unsigned int coreSize = coreStencil_.nRows();
133  unsigned int oldSize = m_.nRows();
134  unsigned int newSize = oldSize;
135 
137  vector< vector< VoxelJunction > > vvj( coreSize );
138 
139  for ( vector< VoxelJunction >::const_iterator
140  i = vj.begin(); i != vj.end(); ++i ) {
141  mmi = meshMap.find( i->second );
142  if ( mmi == meshMap.end() ) {
143  assert( i->first < coreSize );
144  meshBackMap.push_back( i->second );
145  meshMap[i->second] = newSize++;
146  vvj[i->first].push_back( *i );
147  }
148  }
149  vector< vector< VoxelJunction > > vvjCol( newSize );
150  SparseMatrix< double > oldM = m_;
151  m_.clear();
152  m_.setSize( newSize, newSize );
153  for ( unsigned int i = 0; i < newSize; ++i ) {
154  vector< VoxelJunction > temp;
155  if ( i < oldSize ) { // Copy over old matrix.
156  const double* entry;
157  const unsigned int* colIndex;
158  unsigned int num = oldM.getRow( i, &entry, &colIndex );
159  temp.resize( num );
160  for ( unsigned int j = 0; j < num; ++j ) {
161  temp[j].first = colIndex[j];
162  temp[j].diffScale = entry[j];
163  }
164  }
165  if ( i < coreSize ) { // Set up diffusion into proxy voxels.
166  for ( vector< VoxelJunction >::const_iterator
167  j = vvj[i].begin(); j != vvj[i].end(); ++j )
168  {
169  unsigned int row = j->first;
170  assert( row == i );
171  unsigned int col = meshMap[j->second];
172  assert( col >= oldSize );
173  temp.push_back(
174  VoxelJunction( col, EMPTY, j->diffScale ) );
175  vvjCol[col].push_back(
176  VoxelJunction( row, EMPTY, j->diffScale ) );
177  }
178  }
179  if ( i >= oldSize ) { // Set up diffusion from proxy to old voxels
180  for ( vector< VoxelJunction >::const_iterator
181  j = vvjCol[i].begin(); j != vvjCol[i].end(); ++j )
182  {
183  temp.push_back( *j );
184  }
185  }
186  // Now we've filled in all the VoxelJunctions for the new row.
187  sort( temp.begin(), temp.end() );
188  vector< double > e( temp.size() );
189  vector< unsigned int > c( temp.size() );
190  for ( unsigned int j = 0; j < temp.size(); ++j ) {
191  e[j] = temp[j].diffScale;
192  c[j] = temp[j].first;
193  }
194  m_.addRow( i, e, c );
195  }
196 
197  // Fill in the volumes of the external mesh entries
198  for ( vector< unsigned int>::const_iterator
199  i = meshBackMap.begin(); i != meshBackMap.end(); ++i ) {
200  extendedMeshEntryVolume_.push_back( other->getMeshEntryVolume( *i ) );
201  }
202 }
203 
unsigned int getStencilRow(unsigned int meshIndex, const double **entry, const unsigned int **colIndex) const
Definition: MeshCompt.cpp:54
void innerResetStencil()
virtual func implemented here.
Definition: MeshCompt.cpp:49
vector< unsigned int > getNeighbors(unsigned int fid) const
Looks up stencil to return vector of indices of coupled voxels.
Definition: MeshCompt.cpp:69
SparseMatrix< double > m_
Handles stencil for core + abutting voxels.
Definition: MeshCompt.h:77
vector< double > extendedMeshEntryVolume_
Definition: MeshCompt.h:85
unsigned int getRow(unsigned int row, const T **entry, const unsigned int **colIndex) const
Definition: SparseMatrix.h:288
void addRow(unsigned int index, const vector< double > &entry, const vector< unsigned int > &colIndex)
Definition: MeshCompt.cpp:98
double extendedMeshEntryVolume(unsigned int fid) const
Virtual function to return volume of mesh Entry, including.
Definition: MeshCompt.cpp:36
unsigned int nRows() const
Definition: SparseMatrix.h:87
vector< double > innerGetStencilRate(unsigned int row) const
Definition: MeshCompt.cpp:85
void clearExtendedMeshEntryVolume()
Inherited virtual function to clear the vector of MeshEntryVolume.
Definition: MeshCompt.cpp:43
void addRow(unsigned int rowNum, const vector< T > &row)
Definition: SparseMatrix.h:387
void setSize(unsigned int nrows, unsigned int ncolumns)
Definition: SparseMatrix.h:126
static const unsigned int EMPTY
Definition: MeshCompt.cpp:19
void extendStencil(const ChemCompt *other, const vector< VoxelJunction > &vj)
Add boundary voxels to stencil for cross-solver junctions.
Definition: MeshCompt.cpp:121
void setStencilSize(unsigned int numRows, unsigned int numCols)
Definition: MeshCompt.cpp:106
virtual double getMeshEntryVolume(unsigned int fid) const =0
Virtual function to return volume of mesh Entry.
const SparseMatrix< double > & getStencil() const
Returns entire sparse matrix of mesh. Used by diffusion solver.
Definition: MeshCompt.cpp:60
SparseMatrix< double > coreStencil_
Handles the core stencil for own vol.
Definition: MeshCompt.h:74