Memosa-FVM  0.2
CRMatrixRect< T_Coeff, X, B > Class Template Reference

#include <CRMatrixRect.h>

Inheritance diagram for CRMatrixRect< T_Coeff, X, B >:
Collaboration diagram for CRMatrixRect< T_Coeff, X, B >:

Classes

class  PairWiseAssembler
 

Public Types

typedef T_Coeff Coeff
 
typedef T_Coeff Diag
 
typedef T_Coeff OffDiag
 
typedef Array< CoeffCoeffArray
 
typedef Array< CoeffDiagArray
 
typedef Array< X > XArray
 
typedef Array< B > BArray
 
typedef map< const
CRConnectivity
*, PairWiseAssembler * > 
PairWiseAssemblerMap
 

Public Member Functions

 CRMatrixRect (const CRConnectivity &conn)
 
 DEFINE_TYPENAME ("CRMatrixRect<"+NumTypeTraits< Coeff >::getTypeName()+","+NumTypeTraits< X >::getTypeName()+","+NumTypeTraits< B >::getTypeName()+">")
 
virtual void initAssembly ()
 
virtual void multiply (IContainer &yB, const IContainer &xB) const
 
virtual void multiplyAndAdd (IContainer &yB, const IContainer &xB) const
 
const CRConnectivitygetConnectivity () const
 
Array< Coeff > & getDiag ()
 
Array< Coeff > & getOffDiag ()
 
const Array< Coeff > & getDiag () const
 
const Array< Coeff > & getOffDiag () const
 
virtual ~CRMatrixRect ()
 
shared_ptr< CRConnectivitycreateCoarseConnectivity (const IContainer &gCoarseIndex, const CRConnectivity &coarseToFine, const StorageSite &coarseRowSite, const StorageSite &coarseColSite)
 
virtual shared_ptr< MatrixcreateCoarseMatrix (const IContainer &gCoarseIndex, const CRConnectivity &coarseToFine, const CRConnectivity &coarseConnectivity)
 
PairWiseAssemblergetPairWiseAssembler (const CRConnectivity &pairs)
 
- Public Member Functions inherited from Matrix
 Matrix ()
 
virtual ~Matrix ()
 
 DEFINE_TYPENAME ("Matrix")
 
virtual shared_ptr< ArrayBasequadProduct (const IContainer &xB) const
 
virtual void forwardGS (IContainer &xB, IContainer &bB, IContainer &residual) const
 
virtual void reverseGS (IContainer &xB, IContainer &bB, IContainer &residual) const
 
virtual void Jacobi (IContainer &xnew, const IContainer &xold, const IContainer &b) const
 
virtual void iluSolve (IContainer &xB, const IContainer &bB, const IContainer &residual) const
 
virtual void spikeSolve (IContainer &xB, const IContainer &bB, const IContainer &residual, const SpikeStorage &spike_storage) const
 
virtual void solveBoundary (IContainer &xB, IContainer &bB, IContainer &residual) const
 
virtual void computeResidual (const IContainer &xB, const IContainer &bB, IContainer &residual) const
 
virtual int createCoarsening (IContainer &coarseIndex, const int groupSize, const double weighRatioThreshold)
 
virtual void eliminateBoundaryEquations (IContainer &xB)
 
virtual void printRow (const int nr) const
 
virtual void * getDiagData () const
 
virtual void * getOffDiagData () const
 
virtual int getDiagDataSize () const
 
virtual int getOffDiagDataSize () const
 
virtual shared_ptr< MatrixcreateMergeMatrix (const LinearSystemMerger &mergeLS)
 
virtual void setFlatMatrix (Matrix &fmg) const
 
virtual void transpose ()
 
virtual bool isInvertible ()
 

Private Attributes

const CRConnectivity_conn
 
const Array< int > & _row
 
const Array< int > & _col
 
Array< Coeff_diag
 
Array< Coeff_offDiag
 
PairWiseAssemblerMap _pairWiseAssemblers
 

Detailed Description

template<class T_Coeff, class X, class B>
class CRMatrixRect< T_Coeff, X, B >

Sparse matrix stored using a compressed row format. The sparsity pattern is provided by a CRConnectivity object that is required at construction time. Note that we assume that diagonal is implicitly always present (i.e., col[row[i]] through col[row[i+1]] do not contain i) and store diagonal and off diagonal entries in separate arrays.

The class is templated with the types of diagonal, off-diagonal and the corresponsing x arrays as template parameters.

Definition at line 28 of file CRMatrixRect.h.

Member Typedef Documentation

template<class T_Coeff , class X , class B >
typedef Array<B> CRMatrixRect< T_Coeff, X, B >::BArray

Definition at line 37 of file CRMatrixRect.h.

template<class T_Coeff , class X , class B >
typedef T_Coeff CRMatrixRect< T_Coeff, X, B >::Coeff

Definition at line 31 of file CRMatrixRect.h.

template<class T_Coeff , class X , class B >
typedef Array<Coeff> CRMatrixRect< T_Coeff, X, B >::CoeffArray

Definition at line 34 of file CRMatrixRect.h.

template<class T_Coeff , class X , class B >
typedef T_Coeff CRMatrixRect< T_Coeff, X, B >::Diag

Definition at line 32 of file CRMatrixRect.h.

template<class T_Coeff , class X , class B >
typedef Array<Coeff> CRMatrixRect< T_Coeff, X, B >::DiagArray

Definition at line 35 of file CRMatrixRect.h.

template<class T_Coeff , class X , class B >
typedef T_Coeff CRMatrixRect< T_Coeff, X, B >::OffDiag

Definition at line 33 of file CRMatrixRect.h.

template<class T_Coeff , class X , class B >
typedef map<const CRConnectivity*,PairWiseAssembler*> CRMatrixRect< T_Coeff, X, B >::PairWiseAssemblerMap

Definition at line 92 of file CRMatrixRect.h.

template<class T_Coeff , class X , class B >
typedef Array<X> CRMatrixRect< T_Coeff, X, B >::XArray

Definition at line 36 of file CRMatrixRect.h.

Constructor & Destructor Documentation

template<class T_Coeff , class X , class B >
CRMatrixRect< T_Coeff, X, B >::CRMatrixRect ( const CRConnectivity conn)
inline

Definition at line 95 of file CRMatrixRect.h.

References logCtor.

Referenced by CRMatrixRect< T_Coeff, X, B >::createCoarseMatrix().

95  :
96  Matrix(),
97  _conn(conn),
98  _row(_conn.getRow()),
99  _col(_conn.getCol()),
100  _diag(_conn.getRowDim()),
103  {
104  logCtor();
105  }
const Array< int > & getCol() const
const Array< int > & getRow() const
Matrix()
Definition: Matrix.cpp:8
const CRConnectivity & _conn
Definition: CRMatrixRect.h:363
#define logCtor()
Definition: RLogInterface.h:26
const Array< int > & _row
Definition: CRMatrixRect.h:364
const Array< int > & _col
Definition: CRMatrixRect.h:365
Array< Coeff > _diag
Definition: CRMatrixRect.h:366
PairWiseAssemblerMap _pairWiseAssemblers
Definition: CRMatrixRect.h:368
Array< Coeff > _offDiag
Definition: CRMatrixRect.h:367
int getRowDim() const
int getLength() const
Definition: Array.h:87
template<class T_Coeff , class X , class B >
virtual CRMatrixRect< T_Coeff, X, B >::~CRMatrixRect ( )
inlinevirtual

Definition at line 173 of file CRMatrixRect.h.

References logDtor.

174  {
175  logDtor();
176  }
#define logDtor()
Definition: RLogInterface.h:33

Member Function Documentation

template<class T_Coeff , class X , class B >
shared_ptr<CRConnectivity> CRMatrixRect< T_Coeff, X, B >::createCoarseConnectivity ( const IContainer gCoarseIndex,
const CRConnectivity coarseToFine,
const StorageSite coarseRowSite,
const StorageSite coarseColSite 
)
inlinevirtual

Create the connectivity for a coarse level matrix given the coarsening (ie. the fine to coarse index mapping) and its transpose (ie coarse to fine mapping, provided as a CRConnectivity object)

Reimplemented from Matrix.

Definition at line 187 of file CRMatrixRect.h.

References CRMatrixRect< T_Coeff, X, B >::_col, CRMatrixRect< T_Coeff, X, B >::_row, StorageSite::getCount(), and CRConnectivity::getCount().

191  {
192  const Array<int>& coarseIndex =
193  dynamic_cast<const Array<int>& >(gCoarseIndex);
194 
195  const int nCoarseRows = coarseRowSite.getCount();
196 
197  shared_ptr<CRConnectivity> coarseCR(new CRConnectivity(coarseRowSite,coarseColSite));
198 
199 
200  coarseCR->initCount();
201 
202  Array<bool> coarseCounted(nCoarseRows);
203 
204  coarseCounted = false;
205 
206  for(int nrCoarse=0; nrCoarse<nCoarseRows; nrCoarse++)
207  {
208  const int nFine = coarseToFine.getCount(nrCoarse);
209  for(int nfr=0; nfr<nFine; nfr++)
210  {
211  const int nrFine = coarseToFine(nrCoarse,nfr);
212 
213  for (int nb = _row[nrFine]; nb<_row[nrFine+1]; nb++)
214  {
215  const int nc = _col[nb];
216  const int ncCoarse = coarseIndex[nc];
217  if (ncCoarse>=0 && nrCoarse!=ncCoarse && !coarseCounted[ncCoarse])
218  {
219  coarseCounted[ncCoarse] = true;
220  coarseCR->addCount(nrCoarse,1);
221  }
222  }
223  }
224 
225  // reset counted
226  for(int nfr=0; nfr<nFine; nfr++)
227  {
228  const int nrFine = coarseToFine(nrCoarse,nfr);
229 
230  for (int nb = _row[nrFine]; nb<_row[nrFine+1]; nb++)
231  {
232  const int nc = _col[nb];
233  const int ncCoarse = coarseIndex[nc];
234  if (ncCoarse>=0)
235  coarseCounted[ncCoarse] = false;
236  }
237  }
238  }
239 
240  coarseCR->finishCount();
241 
242  for(int nrCoarse=0; nrCoarse<nCoarseRows; nrCoarse++)
243  {
244  const int nFine = coarseToFine.getCount(nrCoarse);
245  for(int nfr=0; nfr<nFine; nfr++)
246  {
247  const int nrFine = coarseToFine(nrCoarse,nfr);
248 
249  for (int nb = _row[nrFine]; nb<_row[nrFine+1]; nb++)
250  {
251  const int nc = _col[nb];
252  const int ncCoarse = coarseIndex[nc];
253  if (ncCoarse>=0 && nrCoarse!=ncCoarse && !coarseCounted[ncCoarse])
254  {
255  coarseCounted[ncCoarse] = true;
256  coarseCR->add(nrCoarse,ncCoarse);
257  }
258  }
259  }
260 
261  // reset counted
262  for(int nfr=0; nfr<nFine; nfr++)
263  {
264  const int nrFine = coarseToFine(nrCoarse,nfr);
265 
266  for (int nb = _row[nrFine]; nb<_row[nrFine+1]; nb++)
267  {
268  const int nc = _col[nb];
269  const int ncCoarse = coarseIndex[nc];
270  if (ncCoarse>=0)
271  coarseCounted[ncCoarse] = false;
272  }
273  }
274  }
275 
276  coarseCR->finishAdd();
277  return coarseCR;
278  }
int getCount(const int i) const
const Array< int > & _row
Definition: CRMatrixRect.h:364
const Array< int > & _col
Definition: CRMatrixRect.h:365
int getCount() const
Definition: StorageSite.h:39
template<class T_Coeff , class X , class B >
virtual shared_ptr<Matrix> CRMatrixRect< T_Coeff, X, B >::createCoarseMatrix ( const IContainer gCoarseIndex,
const CRConnectivity coarseToFine,
const CRConnectivity coarseConnectivity 
)
inlinevirtual

create the coarse matrix given the coarsening and the coarse level connectivity.

Reimplemented from Matrix.

Definition at line 288 of file CRMatrixRect.h.

References CRMatrixRect< T_Coeff, X, B >::_col, CRMatrixRect< T_Coeff, X, B >::_diag, CRMatrixRect< T_Coeff, X, B >::_offDiag, CRMatrixRect< T_Coeff, X, B >::_row, CRMatrixRect< T_Coeff, X, B >::CRMatrixRect(), CRConnectivity::getCol(), CRConnectivity::getCount(), CRConnectivity::getRow(), CRConnectivity::getRowDim(), and Array< T >::zero().

291  {
292  const Array<int>& coarseIndex =
293  dynamic_cast<const Array<int>& >(gCoarseIndex);
294 
295  const int nCoarseRows = coarseConnectivity.getRowDim();
296 
297  shared_ptr<CRMatrixRect> coarseMatrix(new CRMatrixRect(coarseConnectivity));
298 
299  Array<Diag>& coarseDiag = coarseMatrix->getDiag();
300  Array<OffDiag>& coarseOffDiag = coarseMatrix->getOffDiag();
301 
302  const Array<int>& coarseConnRow = coarseConnectivity.getRow();
303  const Array<int>& coarseConnCol = coarseConnectivity.getCol();
304 
305  coarseDiag.zero();
306  coarseOffDiag.zero();
307 
308  //used to avoid searches when inserting coeffs
309  Array<int> coarseCoeffPos(nCoarseRows);
310 
311 
312  for(int nrCoarse=0; nrCoarse<nCoarseRows; nrCoarse++)
313  {
314  // for easy indexing when inserting coefficients set col
315  // positions into the coarse connectivity
316  for(int nb=coarseConnRow[nrCoarse]; nb<coarseConnRow[nrCoarse+1]; nb++)
317  coarseCoeffPos[coarseConnCol[nb]] = nb;
318 
319  // loop over the fine rows that make up this coarse row
320  const int nFine = coarseToFine.getCount(nrCoarse);
321  for(int nfr=0; nfr<nFine; nfr++)
322  {
323  const int nrFine = coarseToFine(nrCoarse,nfr);
324 
325  coarseDiag[nrCoarse] += _diag[nrFine];
326 
327  for (int nb = _row[nrFine]; nb<_row[nrFine+1]; nb++)
328  {
329  const int nc = _col[nb];
330  const int ncCoarse = coarseIndex[nc];
331 
332  if (ncCoarse<0) continue;
333 
334  if (nrCoarse!=ncCoarse)
335  {
336  const int pos = coarseCoeffPos[ncCoarse];
337  coarseOffDiag[pos] += _offDiag[nb];
338  }
339  else
340  {
341  coarseDiag[nrCoarse] += _offDiag[nb];
342  }
343  }
344  }
345  }
346 
347  return coarseMatrix;
348  }
const Array< int > & getCol() const
int getCount(const int i) const
virtual void zero()
Definition: Array.h:281
const Array< int > & getRow() const
const Array< int > & _row
Definition: CRMatrixRect.h:364
const Array< int > & _col
Definition: CRMatrixRect.h:365
Array< Coeff > _diag
Definition: CRMatrixRect.h:366
CRMatrixRect(const CRConnectivity &conn)
Definition: CRMatrixRect.h:95
Array< Coeff > _offDiag
Definition: CRMatrixRect.h:367
int getRowDim() const
template<class T_Coeff , class X , class B >
CRMatrixRect< T_Coeff, X, B >::DEFINE_TYPENAME ( "CRMatrixRect<"+NumTypeTraits< Coeff >::getTypeName()+","+NumTypeTraits< X >::getTypeName()+","+NumTypeTraits< B >::getTypeName()+">"  )
template<class T_Coeff , class X , class B >
const CRConnectivity& CRMatrixRect< T_Coeff, X, B >::getConnectivity ( ) const
inlinevirtual

Reimplemented from Matrix.

Definition at line 165 of file CRMatrixRect.h.

References CRMatrixRect< T_Coeff, X, B >::_conn.

165 {return _conn;}
const CRConnectivity & _conn
Definition: CRMatrixRect.h:363
template<class T_Coeff , class X , class B >
Array<Coeff>& CRMatrixRect< T_Coeff, X, B >::getDiag ( )
inline

Definition at line 167 of file CRMatrixRect.h.

References CRMatrixRect< T_Coeff, X, B >::_diag.

167 {return _diag;}
Array< Coeff > _diag
Definition: CRMatrixRect.h:366
template<class T_Coeff , class X , class B >
const Array<Coeff>& CRMatrixRect< T_Coeff, X, B >::getDiag ( ) const
inline

Definition at line 170 of file CRMatrixRect.h.

References CRMatrixRect< T_Coeff, X, B >::_diag.

170 {return _diag;}
Array< Coeff > _diag
Definition: CRMatrixRect.h:366
template<class T_Coeff , class X , class B >
Array<Coeff>& CRMatrixRect< T_Coeff, X, B >::getOffDiag ( )
inline

Definition at line 168 of file CRMatrixRect.h.

References CRMatrixRect< T_Coeff, X, B >::_offDiag.

168 {return _offDiag;}
Array< Coeff > _offDiag
Definition: CRMatrixRect.h:367
template<class T_Coeff , class X , class B >
const Array<Coeff>& CRMatrixRect< T_Coeff, X, B >::getOffDiag ( ) const
inline

Definition at line 171 of file CRMatrixRect.h.

References CRMatrixRect< T_Coeff, X, B >::_offDiag.

171 {return _offDiag;}
Array< Coeff > _offDiag
Definition: CRMatrixRect.h:367
template<class T_Coeff , class X , class B >
PairWiseAssembler& CRMatrixRect< T_Coeff, X, B >::getPairWiseAssembler ( const CRConnectivity pairs)
inline

Definition at line 350 of file CRMatrixRect.h.

References CRMatrixRect< T_Coeff, X, B >::_conn, CRMatrixRect< T_Coeff, X, B >::_offDiag, CRMatrixRect< T_Coeff, X, B >::_pairWiseAssemblers, and CRConnectivity::getPairToColMapping().

351  {
352  if (_pairWiseAssemblers.find(&pairs) == _pairWiseAssemblers.end())
353  {
354  _pairWiseAssemblers[&pairs] =
355  new PairWiseAssembler(_offDiag,
356  _conn.getPairToColMapping(pairs));
357  }
358  return *_pairWiseAssemblers[&pairs];
359  }
const CRConnectivity & _conn
Definition: CRMatrixRect.h:363
PairWiseAssemblerMap _pairWiseAssemblers
Definition: CRMatrixRect.h:368
Array< Coeff > _offDiag
Definition: CRMatrixRect.h:367
const PairToColMapping & getPairToColMapping(const CRConnectivity &pairs) const
template<class T_Coeff , class X , class B >
virtual void CRMatrixRect< T_Coeff, X, B >::initAssembly ( )
inlinevirtual

Implements Matrix.

Definition at line 114 of file CRMatrixRect.h.

References CRMatrixRect< T_Coeff, X, B >::_diag, CRMatrixRect< T_Coeff, X, B >::_offDiag, and Array< T >::zero().

115  {
116  _diag.zero();
117  _offDiag.zero();
118  }
virtual void zero()
Definition: Array.h:281
Array< Coeff > _diag
Definition: CRMatrixRect.h:366
Array< Coeff > _offDiag
Definition: CRMatrixRect.h:367
template<class T_Coeff , class X , class B >
virtual void CRMatrixRect< T_Coeff, X, B >::multiply ( IContainer yB,
const IContainer xB 
) const
inlinevirtual

y = this * x

Reimplemented from Matrix.

Definition at line 125 of file CRMatrixRect.h.

References CRMatrixRect< T_Coeff, X, B >::_col, CRMatrixRect< T_Coeff, X, B >::_conn, CRMatrixRect< T_Coeff, X, B >::_diag, CRMatrixRect< T_Coeff, X, B >::_offDiag, CRMatrixRect< T_Coeff, X, B >::_row, CRConnectivity::getRowSite(), and StorageSite::getSelfCount().

126  {
127  BArray& y = dynamic_cast<BArray&>(yB);
128  const XArray& x = dynamic_cast<const XArray&>(xB);
129 
130  const int nRows = _conn.getRowSite().getSelfCount();
131  for(int nr=0; nr<nRows; nr++)
132  {
133  y[nr] = _diag[nr]*x[nr];
134  for (int nb = _row[nr]; nb<_row[nr+1]; nb++)
135  {
136  const int j = _col[nb];
137  y[nr] += _offDiag[nb]*x[j];
138  }
139  }
140  }
int getSelfCount() const
Definition: StorageSite.h:40
const CRConnectivity & _conn
Definition: CRMatrixRect.h:363
const Array< int > & _row
Definition: CRMatrixRect.h:364
const Array< int > & _col
Definition: CRMatrixRect.h:365
Array< X > XArray
Definition: CRMatrixRect.h:36
Array< Coeff > _diag
Definition: CRMatrixRect.h:366
Array< B > BArray
Definition: CRMatrixRect.h:37
Array< Coeff > _offDiag
Definition: CRMatrixRect.h:367
const StorageSite & getRowSite() const
template<class T_Coeff , class X , class B >
virtual void CRMatrixRect< T_Coeff, X, B >::multiplyAndAdd ( IContainer yB,
const IContainer xB 
) const
inlinevirtual

y += this * x

Reimplemented from Matrix.

Definition at line 147 of file CRMatrixRect.h.

References CRMatrixRect< T_Coeff, X, B >::_col, CRMatrixRect< T_Coeff, X, B >::_conn, CRMatrixRect< T_Coeff, X, B >::_diag, CRMatrixRect< T_Coeff, X, B >::_offDiag, CRMatrixRect< T_Coeff, X, B >::_row, CRConnectivity::getRowSite(), and StorageSite::getSelfCount().

148  {
149  BArray& y = dynamic_cast<BArray&>(yB);
150  const XArray& x = dynamic_cast<const XArray&>(xB);
151 
152  const int nRows = _conn.getRowSite().getSelfCount();
153  for(int nr=0; nr<nRows; nr++)
154  {
155  y[nr] += _diag[nr]*x[nr];
156  for (int nb = _row[nr]; nb<_row[nr+1]; nb++)
157  {
158  const int j = _col[nb];
159  y[nr] += _offDiag[nb]*x[j];
160  }
161  }
162  }
int getSelfCount() const
Definition: StorageSite.h:40
const CRConnectivity & _conn
Definition: CRMatrixRect.h:363
const Array< int > & _row
Definition: CRMatrixRect.h:364
const Array< int > & _col
Definition: CRMatrixRect.h:365
Array< X > XArray
Definition: CRMatrixRect.h:36
Array< Coeff > _diag
Definition: CRMatrixRect.h:366
Array< B > BArray
Definition: CRMatrixRect.h:37
Array< Coeff > _offDiag
Definition: CRMatrixRect.h:367
const StorageSite & getRowSite() const

Member Data Documentation

template<class T_Coeff , class X , class B >
PairWiseAssemblerMap CRMatrixRect< T_Coeff, X, B >::_pairWiseAssemblers
private

Definition at line 368 of file CRMatrixRect.h.

Referenced by CRMatrixRect< T_Coeff, X, B >::getPairWiseAssembler().


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