Memosa-FVM  0.2
CRMatrixTranspose.h
Go to the documentation of this file.
1 // This file os part of FVM
2 // Copyright (c) 2012 FVM Authors
3 // See LICENSE file for terms.
4 
5 #ifndef _CRMATRIXTRANSPOSE_H_
6 #define _CRMATRIXTRANSPOSE_H_
7 
8 
9 #include "Matrix.h"
10 #include "CRConnectivity.h"
11 #include "Array.h"
12 #include "StorageSite.h"
13 
14 
40 template<class T_Coeff, class X, class B>
41 class CRMatrixTranspose : public Matrix
42 {
43 public:
44  typedef T_Coeff Coeff;
46  typedef Array<X> XArray;
47  typedef Array<B> BArray;
48 
49 
51  Matrix(),
52  _conn(conn),
53  _row(_conn.getRow()),
54  _col(_conn.getCol()),
55  _coeffPtr(new CoeffArray(_col.getLength())),
57  {
58  logCtor();
59  }
60 
61  // meant to be used to create CRMatrixTranspose<T,Vec3,Vec3> from
62  // CRMatrix<T,T,T>
63 
64  template<class X2, class B2>
66  Matrix(),
68  _row(_conn.getRow()),
69  _col(_conn.getCol()),
72  {
73  logCtor();
74  }
75 
76 
77  DEFINE_TYPENAME("CRMatrixTranspose<"
81  +">");
82 
83  virtual void initAssembly()
84  {
85  _coeff.zero();
86  }
87 
93  virtual void multiply(IContainer& yB, const IContainer& xB) const
94  {
95  yB.zero();
96  this->multiplyAndAdd(yB,xB);
97  }
98 
104  virtual void multiplyAndAdd(IContainer& yB, const IContainer& xB) const
105  {
106  BArray& y = dynamic_cast<BArray&>(yB);
107  const XArray& x = dynamic_cast<const XArray&>(xB);
108 
109  const int nRows = _conn.getRowSite().getCount();
110  for(int nr=0; nr<nRows; nr++)
111  {
112  for (int nb = _row[nr]; nb<_row[nr+1]; nb++)
113  {
114  const int j = _col[nb];
115  y[nr] += _coeff[nb]*x[j];
116  }
117  }
118  }
119 
120 
121  const CRConnectivity& getConnectivity() const {return _conn;}
122 
124  const Array<Coeff>& getCoeff() const {return _coeff;}
125  shared_ptr<Array<Coeff> > getCoeffPtr() const {return _coeffPtr;}
126 
127 private:
129  const Array<int>& _row;
130  const Array<int>& _col;
131  shared_ptr<Array<Coeff> > _coeffPtr;
133 };
134 
135 #endif
136 
virtual void multiply(IContainer &yB, const IContainer &xB) const
virtual void zero()
Definition: Array.h:281
const Array< int > & _col
virtual void initAssembly()
shared_ptr< Array< Coeff > > getCoeffPtr() const
CRMatrixTranspose(const CRConnectivity &conn)
#define logCtor()
Definition: RLogInterface.h:26
const Array< Coeff > & getCoeff() const
const CRConnectivity & getConnectivity() const
Array< Coeff > & getCoeff()
CRMatrixTranspose(const CRMatrixTranspose< Coeff, X2, B2 > &m)
Definition: Matrix.h:16
shared_ptr< Array< Coeff > > _coeffPtr
virtual void multiplyAndAdd(IContainer &yB, const IContainer &xB) const
Array< Coeff > & _coeff
int getCount() const
Definition: StorageSite.h:39
const Array< int > & _row
Array< Coeff > CoeffArray
DEFINE_TYPENAME("CRMatrixTranspose<"+NumTypeTraits< Coeff >::getTypeName()+","+NumTypeTraits< X >::getTypeName()+","+NumTypeTraits< B >::getTypeName()+">")
const CRConnectivity & _conn
const StorageSite & getRowSite() const
virtual void zero()=0