5 #ifndef _GRADIENTMATRIX_H_
6 #define _GRADIENTMATRIX_H_
23 typedef pair<const StorageSite*, const StorageSite*>
EntryIndex;
30 template<
class T_Scalar>
39 _conn(mesh.getCellCellsGhostExt()),
43 _conn(mesh.getCellCells()),
56 shared_ptr<Array<Gradient<X> > >
62 shared_ptr<GradArray> gradXPtr(
new GradArray(x.
getLength()));
63 GradArray& gradX = *gradXPtr;
66 for(
int nr=0; nr<nRows; nr++)
69 for (
int nb =
_row[nr]; nb<
_row[nr+1]; nb++)
71 const int j =
_col[nb];
72 gradX[nr].accumulate(
_coeffs[nb],x[j]-x[nr]);
88 for (
int nb = _row[i]; nb<_row[i+1]; nb++)
90 const int j =
_col[nb];
117 for (
int nb = _row[i]; nb<_row[i+1]; nb++)
119 const int j =
_col[nb];
131 for (
int nnb =
_row[i]; nnb<
_row[i+1]; nnb++)
143 for (
int nnb =
_row[i]; nnb<
_row[i+1]; nnb++)
199 foreach(
const StorageSite::ScatterMap::value_type& mpos, scatterMap){
201 const Array<int>& scatterArray = *mpos.second;
205 for (
int i = 0; i < scatterArray.
getLength(); i++ ){
206 sendSize += cellCells.
getCount( scatterArray[i] );
209 _sendValues[e] = shared_ptr< Array<Coord> > (
new Array<Coord> (sendSize) );
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);
224 foreach(
const StorageSite::GatherMap::value_type& mpos, gatherMap){
230 for (
int i = 0; i < recvCounts.
getLength(); i++ ){
231 recvSize += recvCounts[i];
234 _recvValues [e] = shared_ptr< Array<Coord> > (
new Array<Coord> (recvSize) );
246 foreach(
const StorageSite::GatherMap::value_type& mpos, gatherMap){
252 *_recvValues[e] = *_sendValues [e];
264 MPI::Request request_send[ request_size ];
265 MPI::Request request_recv[ request_size ];
270 foreach(
const StorageSite::ScatterMap::value_type& mpos, scatterMap){
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 );
286 foreach(
const StorageSite::GatherMap::value_type& mpos, gatherMap){
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 );
300 MPI::Request::Waitall( count, request_recv );
301 MPI::Request::Waitall( count, request_send );
308 foreach(
const StorageSite::GatherMap::value_type& mpos, gatherMap){
313 if ( from_where != -1 ){
321 for (
int i = 0; i < gatherArray.
getLength(); i++ ){
322 const int ii = gatherArray[i];
323 const int nnb = recv_counts[i];
324 for (
int nb = 0; nb < nnb; nb++ ){
325 const int jj = globalToLocal.find( recv_indices[indx] )->second;
327 matrix_entry = recv_values[indx];
348 foreach(
const StorageSite::ScatterMap::value_type& mpos, scatterMap){
361 for (
int nb =
_row[i]; nb<
_row[i+1]; nb++)
363 const int j =
_col[nb];
364 cout <<
"coeff (" << i <<
"," << j <<
") = " <<
_coeffs[nb] << endl;
GradientMatrix(const Mesh &mesh)
int getCount(const int i) const
virtual int getDataSize() const =0
const Array< Coord > & getCoeffs() const
const Array< int > & _row
Coord & getCoeff01(const int np)
Coord & getCoeff10(const int np)
const ArrayBase & getRecvIndices(const EntryIndex &e) const
X computeR(const Gradient< X > &g, const Array< X > &x, const Coord dist, int i, int j) const
Coord & getCoeff(const int i, const int j)
PairWiseAssembler & getPairWiseAssembler(const CRConnectivity &pairs)
map< int, int > & getGlobalToLocal()
pair< const StorageSite *, const StorageSite * > EntryIndex
const Coord & getCoeff(const int i, const int j) const
PairWiseAssembler(Array< Coord > &coeffs, const Array< Vector< int, 2 > > &pairToCol)
const Array< Vector< int, 2 > > & _pairToCol
virtual void printRow(const int i) const
Vector< T_Scalar, 3 > Coord
Array< Coord > & getCoeffs()
const CRConnectivity & getConnectivity() const
int getGatherProcID() const
const ArrayBase & getRecvCounts(const EntryIndex &e) const
map< EntryIndex, shared_ptr< ArrayBase > > GhostArrayMap
const CRConnectivity & getCellCells() const
const StorageSite & getCells() const
const CRConnectivity & _conn
void accumulate(const Coord &wt, const T &v)
const ScatterMap & getScatterMap() const
virtual ~GradientMatrix()
map< const StorageSite *, shared_ptr< Array< int > > > ScatterMap
virtual ~GradientMatrixBase()
shared_ptr< Array< Gradient< X > > > getGradient(const Array< X > &x) const
const GatherMap & getGatherMap() const
void recvScatterGatherValuesBufferLocal()
virtual void * getData() const =0
void computeFaceGradient(Gradient< X > &g, const Array< X > &x, int i) const
map< const StorageSite *, shared_ptr< Array< int > > > GatherMap
void computeGradient(Gradient< X > &g, const Array< X > &x, int i) const
const StorageSite & getRowSite() const
map< const CRConnectivity *, PairWiseAssembler * > _pairWiseAssemblers
const Array< int > & _col
void createScatterGatherValuesBuffer()