Memosa-FVM  0.2
GradientMatrix< T_Scalar > Class Template Reference

#include <GradientMatrix.h>

Inheritance diagram for GradientMatrix< T_Scalar >:
Collaboration diagram for GradientMatrix< T_Scalar >:

Classes

class  PairWiseAssembler
 

Public Types

typedef Vector< T_Scalar, 3 > Coord
 
- Public Types inherited from GradientMatrixBase
typedef pair< const
StorageSite *, const
StorageSite * > 
EntryIndex
 
typedef map< EntryIndex,
shared_ptr< ArrayBase > > 
GhostArrayMap
 

Public Member Functions

 GradientMatrix (const Mesh &mesh)
 
virtual ~GradientMatrix ()
 
template<class X >
shared_ptr< Array< Gradient< X > > > getGradient (const Array< X > &x) const
 
template<class X >
void computeGradient (Gradient< X > &g, const Array< X > &x, int i) const
 
template<class X >
computeR (const Gradient< X > &g, const Array< X > &x, const Coord dist, int i, int j) const
 
template<class X >
void computeFaceGradient (Gradient< X > &g, const Array< X > &x, int i) const
 
const CRConnectivitygetConnectivity () const
 
Array< Coord > & getCoeffs ()
 
const Array< Coord > & getCoeffs () const
 
CoordgetCoeff (const int i, const int j)
 
const CoordgetCoeff (const int i, const int j) const
 
PairWiseAssemblergetPairWiseAssembler (const CRConnectivity &pairs)
 
void createScatterGatherValuesBuffer ()
 
void recvScatterGatherValuesBufferLocal ()
 
void syncValues ()
 
- Public Member Functions inherited from GradientMatrixBase
 GradientMatrixBase ()
 
virtual void syncLocal ()
 
virtual ~GradientMatrixBase ()
 

Private Member Functions

int get_request_size ()
 
virtual void printRow (const int i) const
 

Private Attributes

const Mesh_mesh
 
const CRConnectivity_conn
 
const Array< int > & _row
 
const Array< int > & _col
 
Array< Coord_coeffs
 
map< const CRConnectivity
*, PairWiseAssembler * > 
_pairWiseAssemblers
 

Detailed Description

template<class T_Scalar>
class GradientMatrix< T_Scalar >

Definition at line 31 of file GradientMatrix.h.

Member Typedef Documentation

template<class T_Scalar>
typedef Vector<T_Scalar,3> GradientMatrix< T_Scalar >::Coord

Definition at line 34 of file GradientMatrix.h.

Constructor & Destructor Documentation

template<class T_Scalar>
GradientMatrix< T_Scalar >::GradientMatrix ( const Mesh mesh)
inline

Definition at line 36 of file GradientMatrix.h.

36  :
37  _mesh(mesh),
38 #ifdef FVM_PARALLEL
40  _row(_conn.getRow() ),
41  _col(_conn.getCol() ),
42 #else
43  _conn(mesh.getCellCells()),
44  _row(_conn.getRow()),
45  _col(_conn.getCol()),
46 #endif
49  {
50  }
const Array< int > & getCol() const
const Array< int > & getRow() const
const Array< int > & _row
const Mesh & _mesh
const CRConnectivity & getCellCellsGhostExt() const
Definition: Mesh.h:267
Array< Coord > _coeffs
const CRConnectivity & getCellCells() const
Definition: Mesh.cpp:480
const CRConnectivity & _conn
map< const CRConnectivity *, PairWiseAssembler * > _pairWiseAssemblers
const Array< int > & _col
int getLength() const
Definition: Array.h:87
template<class T_Scalar>
virtual GradientMatrix< T_Scalar >::~GradientMatrix ( )
inlinevirtual

Definition at line 52 of file GradientMatrix.h.

53  {}

Member Function Documentation

template<class T_Scalar>
template<class X >
void GradientMatrix< T_Scalar >::computeFaceGradient ( Gradient< X > &  g,
const Array< X > &  x,
int  i 
) const
inline

Definition at line 109 of file GradientMatrix.h.

References GradientMatrix< T_Scalar >::_coeffs, GradientMatrix< T_Scalar >::_col, GradientMatrix< T_Scalar >::_row, Gradient< T >::accumulate(), and Gradient< T >::zero().

110  {
111  g.zero();
112 
113  // for boundaries use the adjacent cell
114  if (_row[i+1] - _row[i] == 1)
115  i = _col[_row[i]];
116 
117  for (int nb = _row[i]; nb<_row[i+1]; nb++)
118  {
119  const int j = _col[nb];
120  g.accumulate(_coeffs[nb],x[j]);
121  }
122  }
const Array< int > & _row
Array< Coord > _coeffs
void accumulate(const Coord &wt, const T &v)
Definition: Gradient.h:57
void zero()
Definition: Gradient.h:122
const Array< int > & _col
template<class T_Scalar>
template<class X >
void GradientMatrix< T_Scalar >::computeGradient ( Gradient< X > &  g,
const Array< X > &  x,
int  i 
) const
inline

Definition at line 80 of file GradientMatrix.h.

References GradientMatrix< T_Scalar >::_coeffs, GradientMatrix< T_Scalar >::_col, GradientMatrix< T_Scalar >::_row, Gradient< T >::accumulate(), and Gradient< T >::zero().

81  {
82  g.zero();
83 
84  // for boundaries use the adjacent cell
85  if (_row[i+1] - _row[i] == 1)
86  i = _col[_row[i]];
87 
88  for (int nb = _row[i]; nb<_row[i+1]; nb++)
89  {
90  const int j = _col[nb];
91  g.accumulate(_coeffs[nb],x[j]-x[i]);
92  }
93  }
const Array< int > & _row
Array< Coord > _coeffs
void accumulate(const Coord &wt, const T &v)
Definition: Gradient.h:57
void zero()
Definition: Gradient.h:122
const Array< int > & _col
template<class T_Scalar>
template<class X >
X GradientMatrix< T_Scalar >::computeR ( const Gradient< X > &  g,
const Array< X > &  x,
const Coord  dist,
int  i,
int  j 
) const
inline

Definition at line 97 of file GradientMatrix.h.

Referenced by COMETBoundaryConditions< X, Diag, OffDiag >::applyPressureInletBC(), COMETBoundaryConditions< X, Diag, OffDiag >::applyRealWallBC(), COMETBoundaryConditions< X, Diag, OffDiag >::applyZeroGradientBC(), COMETESBGKDiscretizer< T >::COMETConvectionFine(), and COMETESBGKDiscretizer< T >::setBoundaryValFine().

98  {//Darwish and Moukalled, Int. J. H. M. T., 46 (2003) 599-611
99 
100  X den=x[j]-x[i];
101  X num=2.*(g*dist);
102  if (den!=0.)
103  return num/den-1.;
104  return 0;
105  }
template<class T_Scalar>
void GradientMatrix< T_Scalar >::createScatterGatherValuesBuffer ( )
inline

Definition at line 192 of file GradientMatrix.h.

References GradientMatrix< T_Scalar >::_mesh, Mesh::getCellCells(), Mesh::getCells(), GradientMatrix< T_Scalar >::getCoeff(), CRConnectivity::getCount(), StorageSite::getGatherMap(), Array< T >::getLength(), Mesh::getRecvCounts(), and StorageSite::getScatterMap().

Referenced by GradientModel< Vector< T, 3 > >::compute().

193  {
194 #ifdef FVM_PARALLEL
195  //SENDING allocation and filling
196  const StorageSite& site = _mesh.getCells();
197  const CRConnectivity& cellCells = _mesh.getCellCells();
198  const StorageSite::ScatterMap& scatterMap = site.getScatterMap();
199  foreach(const StorageSite::ScatterMap::value_type& mpos, scatterMap){
200  const StorageSite& oSite = *mpos.first;
201  const Array<int>& scatterArray = *mpos.second;
202  //loop over surround indices and itself for sizing
203  EntryIndex e(&site,&oSite);
204  int sendSize = 0;
205  for ( int i = 0; i < scatterArray.getLength(); i++ ){
206  sendSize += cellCells.getCount( scatterArray[i] );
207  }
208  //allocate array
209  _sendValues[e] = shared_ptr< Array<Coord> > ( new Array<Coord> (sendSize) );
210  //fill send array
211  Array<Coord>& valueArray = dynamic_cast< Array<Coord>& > ( *_sendValues[e] );
212  int indx = 0;
213  for( int i = 0; i < scatterArray.getLength(); i++ ){
214  const int ii = scatterArray[i];
215  for ( int j = 0; j < cellCells.getCount(ii); j++ ){
216  const int jj = cellCells(ii,j);
217  valueArray[indx] = getCoeff(ii,jj);
218  indx++;
219  }
220  }
221  }
222  //RECIEVING allocation (filling will be done by MPI Communication)
223  const StorageSite::GatherMap& gatherMap = site.getGatherMap();
224  foreach(const StorageSite::GatherMap::value_type& mpos, gatherMap){
225  const StorageSite& oSite = *mpos.first;
226  EntryIndex e(&oSite,&site);
227  //get recvSize
228  const Array<int>& recvCounts = dynamic_cast< const Array<int>& > (_mesh.getRecvCounts(e));
229  int recvSize = 0;
230  for ( int i = 0; i < recvCounts.getLength(); i++ ){
231  recvSize += recvCounts[i];
232  }
233  //allocate array
234  _recvValues [e] = shared_ptr< Array<Coord> > ( new Array<Coord> (recvSize) );
235  }
236 #endif
237  }
int getCount(const int i) const
const Mesh & _mesh
Coord & getCoeff(const int i, const int j)
pair< const StorageSite *, const StorageSite * > EntryIndex
const ArrayBase & getRecvCounts(const EntryIndex &e) const
Definition: Mesh.h:280
const CRConnectivity & getCellCells() const
Definition: Mesh.cpp:480
const StorageSite & getCells() const
Definition: Mesh.h:109
const ScatterMap & getScatterMap() const
Definition: StorageSite.h:58
map< const StorageSite *, shared_ptr< Array< int > > > ScatterMap
Definition: StorageSite.h:23
const GatherMap & getGatherMap() const
Definition: StorageSite.h:59
map< const StorageSite *, shared_ptr< Array< int > > > GatherMap
Definition: StorageSite.h:24
int getLength() const
Definition: Array.h:87
template<class T_Scalar>
int GradientMatrix< T_Scalar >::get_request_size ( )
inlineprivate

Definition at line 343 of file GradientMatrix.h.

References GradientMatrix< T_Scalar >::_mesh, Mesh::getCells(), StorageSite::getGatherProcID(), and StorageSite::getScatterMap().

Referenced by GradientMatrix< T_Scalar >::syncValues().

344  {
345  int indx = 0;
346  const StorageSite& site = _mesh.getCells();
347  const StorageSite::ScatterMap& scatterMap = site.getScatterMap();
348  foreach(const StorageSite::ScatterMap::value_type& mpos, scatterMap){
349  const StorageSite& oSite = *mpos.first;
350  //checking if storage site is only site or ghost site, we only communicate ghost site ( oSite.getCount() == -1 )
351  if ( oSite.getGatherProcID() != -1 )
352  indx++;
353  }
354  return indx;
355  }
const Mesh & _mesh
int getGatherProcID() const
Definition: StorageSite.h:83
const StorageSite & getCells() const
Definition: Mesh.h:109
const ScatterMap & getScatterMap() const
Definition: StorageSite.h:58
map< const StorageSite *, shared_ptr< Array< int > > > ScatterMap
Definition: StorageSite.h:23
template<class T_Scalar>
Coord& GradientMatrix< T_Scalar >::getCoeff ( const int  i,
const int  j 
)
inline
template<class T_Scalar>
const Coord& GradientMatrix< T_Scalar >::getCoeff ( const int  i,
const int  j 
) const
inline

Definition at line 141 of file GradientMatrix.h.

References GradientMatrix< T_Scalar >::_coeffs, GradientMatrix< T_Scalar >::_col, and GradientMatrix< T_Scalar >::_row.

142  {
143  for (int nnb = _row[i]; nnb<_row[i+1]; nnb++)
144  {
145  if (_col[nnb] == j)
146  return _coeffs[nnb];
147  }
148  throw CException("invalid indices");
149  }
const Array< int > & _row
Array< Coord > _coeffs
const Array< int > & _col
template<class T_Scalar>
const Array<Coord>& GradientMatrix< T_Scalar >::getCoeffs ( ) const
inline

Definition at line 127 of file GradientMatrix.h.

References GradientMatrix< T_Scalar >::_coeffs.

127 {return _coeffs;}
Array< Coord > _coeffs
template<class T_Scalar>
template<class X >
shared_ptr<Array<Gradient<X> > > GradientMatrix< T_Scalar >::getGradient ( const Array< X > &  x) const
inline

Definition at line 57 of file GradientMatrix.h.

References GradientMatrix< T_Scalar >::_coeffs, GradientMatrix< T_Scalar >::_col, GradientMatrix< T_Scalar >::_row, GradientMatrix< T_Scalar >::getConnectivity(), Array< T >::getLength(), CRConnectivity::getRowSite(), and StorageSite::getSelfCount().

Referenced by GradientModel< Vector< T, 3 > >::compute().

58  {
59  typedef Gradient<X> GradType;
60  typedef Array<GradType> GradArray;
61 
62  shared_ptr<GradArray> gradXPtr(new GradArray(x.getLength()));
63  GradArray& gradX = *gradXPtr;
64 
65  const int nRows = getConnectivity().getRowSite().getSelfCount();
66  for(int nr=0; nr<nRows; nr++)
67  {
68  gradX[nr].zero();
69  for (int nb = _row[nr]; nb<_row[nr+1]; nb++)
70  {
71  const int j = _col[nb];
72  gradX[nr].accumulate(_coeffs[nb],x[j]-x[nr]);
73  }
74  }
75  return gradXPtr;
76  }
int getSelfCount() const
Definition: StorageSite.h:40
const Array< int > & _row
const CRConnectivity & getConnectivity() const
Array< Coord > _coeffs
Definition: Array.h:14
const StorageSite & getRowSite() const
const Array< int > & _col
int getLength() const
Definition: Array.h:87
template<class T_Scalar>
PairWiseAssembler& GradientMatrix< T_Scalar >::getPairWiseAssembler ( const CRConnectivity pairs)
inline

Definition at line 179 of file GradientMatrix.h.

References GradientMatrix< T_Scalar >::_coeffs, GradientMatrix< T_Scalar >::_pairWiseAssemblers, and GradientMatrix< T_Scalar >::getConnectivity().

Referenced by GradientModel< Vector< T, 3 > >::compute(), GradientModel< Vector< T, 3 > >::getLeastSquaresGradientMatrix2D(), and GradientModel< Vector< T, 3 > >::getLeastSquaresGradientMatrix3D().

180  {
181  if (_pairWiseAssemblers.find(&pairs) == _pairWiseAssemblers.end())
182  {
183  _pairWiseAssemblers[&pairs] =
184  new PairWiseAssembler(_coeffs,
185  getConnectivity().getPairToColMapping(pairs));
186  }
187  return *_pairWiseAssemblers[&pairs];
188  }
const CRConnectivity & getConnectivity() const
Array< Coord > _coeffs
map< const CRConnectivity *, PairWiseAssembler * > _pairWiseAssemblers
template<class T_Scalar>
virtual void GradientMatrix< T_Scalar >::printRow ( const int  i) const
inlineprivatevirtual

Definition at line 358 of file GradientMatrix.h.

References GradientMatrix< T_Scalar >::_coeffs, GradientMatrix< T_Scalar >::_col, and GradientMatrix< T_Scalar >::_row.

359  {
360 
361  for (int nb = _row[i]; nb<_row[i+1]; nb++)
362  {
363  const int j = _col[nb];
364  cout << "coeff (" << i << "," << j << ") = " << _coeffs[nb] << endl;
365  }
366  }
const Array< int > & _row
Array< Coord > _coeffs
const Array< int > & _col
template<class T_Scalar>
void GradientMatrix< T_Scalar >::recvScatterGatherValuesBufferLocal ( )
inline

Definition at line 240 of file GradientMatrix.h.

References GradientMatrix< T_Scalar >::_mesh, Mesh::getCells(), StorageSite::getGatherMap(), and StorageSite::getGatherProcID().

Referenced by GradientModel< Vector< T, 3 > >::compute().

241  {
242 #ifdef FVM_PARALLEL
243  //RECIEVING allocation (filling will be done by MPI Communication)
244  const StorageSite& site = _mesh.getCells();
245  const StorageSite::GatherMap& gatherMap = site.getGatherMap();
246  foreach(const StorageSite::GatherMap::value_type& mpos, gatherMap){
247  const StorageSite& oSite = *mpos.first;
248  EntryIndex e(&oSite,&site);
249  //get recvSize
250  //mesh interface can be done know
251  if ( oSite.getGatherProcID() == - 1) {
252  *_recvValues[e] = *_sendValues [e];
253  }
254  }
255 #endif
256  }
const Mesh & _mesh
pair< const StorageSite *, const StorageSite * > EntryIndex
int getGatherProcID() const
Definition: StorageSite.h:83
const StorageSite & getCells() const
Definition: Mesh.h:109
const GatherMap & getGatherMap() const
Definition: StorageSite.h:59
map< const StorageSite *, shared_ptr< Array< int > > > GatherMap
Definition: StorageSite.h:24
template<class T_Scalar>
void GradientMatrix< T_Scalar >::syncValues ( )
inline

Definition at line 259 of file GradientMatrix.h.

References GradientMatrix< T_Scalar >::_mesh, GradientMatrix< T_Scalar >::get_request_size(), Mesh::getCells(), GradientMatrix< T_Scalar >::getCoeff(), ArrayBase::getData(), ArrayBase::getDataSize(), StorageSite::getGatherMap(), StorageSite::getGatherProcID(), Mesh::getGlobalToLocal(), Array< T >::getLength(), Mesh::getRecvCounts(), Mesh::getRecvIndices(), StorageSite::getScatterMap(), and StorageSite::getTag().

Referenced by GradientModel< Vector< T, 3 > >::compute().

260  {
261 #ifdef FVM_PARALLEL
262  //SENDING
263  const int request_size = get_request_size();
264  MPI::Request request_send[ request_size ];
265  MPI::Request request_recv[ request_size ];
266  int indxSend = 0;
267  int indxRecv = 0;
268  const StorageSite& site = _mesh.getCells();
269  const StorageSite::ScatterMap& scatterMap = site.getScatterMap();
270  foreach(const StorageSite::ScatterMap::value_type& mpos, scatterMap){
271  const StorageSite& oSite = *mpos.first;
272  EntryIndex e(&site,&oSite);
273  //checking if storage site is only site or ghost site, we only communicate ghost site ( oSite.getCount() == -1 )
274  ArrayBase& sendArray = *_sendValues[e];
275  //loop over surround indices and itself
276  int to_where = oSite.getGatherProcID();
277  if ( to_where != -1 ){
278  int mpi_tag = oSite.getTag();
279  request_send[indxSend++] =
280  MPI::COMM_WORLD.Isend( sendArray.getData(), sendArray.getDataSize(), MPI::BYTE, to_where, mpi_tag );
281  }
282  }
283  //RECIEVING
284  //getting values from other meshes to fill g
285  const StorageSite::GatherMap& gatherMap = site.getGatherMap();
286  foreach(const StorageSite::GatherMap::value_type& mpos, gatherMap){
287  const StorageSite& oSite = *mpos.first;
288  //checking if storage site is only site or ghost site, we only communicate ghost site ( oSite.getCount() == -1 )
289  EntryIndex e(&oSite,&site);
290  ArrayBase& recvArray = *_recvValues[e];
291  int from_where = oSite.getGatherProcID();
292  if ( from_where != -1 ){
293  int mpi_tag = oSite.getTag();
294  request_recv[indxRecv++] =
295  MPI::COMM_WORLD.Irecv( recvArray.getData(), recvArray.getDataSize(), MPI::BYTE, from_where, mpi_tag );
296  }
297  }
298 
299  int count = get_request_size();
300  MPI::Request::Waitall( count, request_recv );
301  MPI::Request::Waitall( count, request_send );
302 
303 // const StorageSite& site = _mesh.getCells();
304 // const StorageSite::GatherMap& gatherMap = site.getGatherMap();
305 
306  //replacing values
307  const map<int,int>& globalToLocal = _mesh.getGlobalToLocal();
308  foreach(const StorageSite::GatherMap::value_type& mpos, gatherMap){
309  const StorageSite& oSite = *mpos.first;
310  const Array<int>& gatherArray = dynamic_cast< const Array<int>& > (*mpos.second);
311  //checking if storage site is only site or ghost site, we only communicate ghost site ( oSite.getCount() == -1 )
312  int from_where = oSite.getGatherProcID();
313  if ( from_where != -1 ){
314  EntryIndex e(&oSite,&site);
315  const Array<int> & recv_counts = dynamic_cast< const Array<int>& > (_mesh.getRecvCounts(e) );
316  const Array<int> & recv_indices = dynamic_cast< const Array<int>& > (_mesh.getRecvIndices(e));
317  const Array<Coord>& recv_values = dynamic_cast< const Array<Coord>& > (*_recvValues [e]);
318 
319  //loop over gatherArray
320  int indx = 0;
321  for ( int i = 0; i < gatherArray.getLength(); i++ ){
322  const int ii = gatherArray[i];
323  const int nnb = recv_counts[i]; //give getCount()
324  for ( int nb = 0; nb < nnb; nb++ ){
325  const int jj = globalToLocal.find( recv_indices[indx] )->second;
326  Coord& matrix_entry = getCoeff(ii,jj);
327  matrix_entry = recv_values[indx];
328  indx++;
329  }
330  }
331  }
332  }
333 
334 #endif
335  }
virtual int getDataSize() const =0
const Mesh & _mesh
const ArrayBase & getRecvIndices(const EntryIndex &e) const
Definition: Mesh.h:281
Coord & getCoeff(const int i, const int j)
map< int, int > & getGlobalToLocal()
Definition: Mesh.h:243
pair< const StorageSite *, const StorageSite * > EntryIndex
Vector< T_Scalar, 3 > Coord
int getTag() const
Definition: StorageSite.h:84
int getGatherProcID() const
Definition: StorageSite.h:83
const ArrayBase & getRecvCounts(const EntryIndex &e) const
Definition: Mesh.h:280
const StorageSite & getCells() const
Definition: Mesh.h:109
const ScatterMap & getScatterMap() const
Definition: StorageSite.h:58
map< const StorageSite *, shared_ptr< Array< int > > > ScatterMap
Definition: StorageSite.h:23
const GatherMap & getGatherMap() const
Definition: StorageSite.h:59
virtual void * getData() const =0
map< const StorageSite *, shared_ptr< Array< int > > > GatherMap
Definition: StorageSite.h:24
int getLength() const
Definition: Array.h:87

Member Data Documentation

template<class T_Scalar>
const CRConnectivity& GradientMatrix< T_Scalar >::_conn
private

Definition at line 369 of file GradientMatrix.h.

Referenced by GradientMatrix< T_Scalar >::getConnectivity().

template<class T_Scalar>
map<const CRConnectivity*,PairWiseAssembler*> GradientMatrix< T_Scalar >::_pairWiseAssemblers
mutableprivate

Definition at line 375 of file GradientMatrix.h.

Referenced by GradientMatrix< T_Scalar >::getPairWiseAssembler().


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