FEI  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fei_EqnCommMgr.hpp
1 #ifndef _fei_EqnCommMgr_hpp_
2 #define _fei_EqnCommMgr_hpp_
3 
4 /*--------------------------------------------------------------------*/
5 /* Copyright 2005 Sandia Corporation. */
6 /* Under the terms of Contract DE-AC04-94AL85000, there is a */
7 /* non-exclusive license for use of this work by or on behalf */
8 /* of the U.S. Government. Export of this program may require */
9 /* a license from the United States Government. */
10 /*--------------------------------------------------------------------*/
11 
12 #include "fei_fwd.hpp"
13 #include "fei_mpi.h"
14 
15 #include "snl_fei_PointBlockMap.hpp"
16 
17 #include <fei_CSRMat.hpp>
18 #include <fei_CSVec.hpp>
19 #include <fei_CommUtils.hpp>
20 #include "fei_ProcEqns.hpp"
21 #include "fei_EqnBuffer.hpp"
22 
104 class EqnCommMgr {
105  public:
109  EqnCommMgr(MPI_Comm comm, bool accumulate = true);
110 
112  EqnCommMgr(const EqnCommMgr& src);
113 
115  EqnCommMgr& operator=(const EqnCommMgr& src);
116 
118  virtual ~EqnCommMgr();
119 
121  EqnCommMgr* deepCopy();
122 
126  size_t getNumSharingProcs() {return(recvProcEqns_->getNumProcs());};
127  std::vector<int>& sharingProcsPtr() {return(recvProcEqns_->procsPtr());};
128 
132  size_t getNumOwnerProcs() {return(sendProcEqns_->getNumProcs());};
133  std::vector<int>& ownerProcsPtr() {return(sendProcEqns_->procsPtr());};
134 
136  void addLocalEqn(int eqnNumber, int srcProc);
137 
138  void addSolnValues(int* eqnNumbers, double* values, int num);
139 
140 #ifdef FEI_HAVE_IOSFWD
141  int exchangeIndices(std::ostream* dbgOut=NULL);
142  int exchangeEqns(std::ostream* dbgOut=NULL);
143 #else
144  int exchangeIndices(ostream* dbgOut=NULL);
145  int exchangeEqns(ostream* dbgOut=NULL);
146 #endif
147 
148  void exchangeSoln();
149 
173  int mirrorProcEqns(ProcEqns& inProcEqns, ProcEqns& outProcEqns);
174 
187  int mirrorProcEqnLengths(ProcEqns& inProcEqns,
188  ProcEqns& outProcEqns);
189 
190 
191  static int exchangeEqnBuffers(MPI_Comm comm, ProcEqns* sendProcEqns,
192  EqnBuffer* sendEqns, ProcEqns* recvProcEqns,
193  EqnBuffer* recvEqns, bool accumulate);
194 
195  int getNumLocalEqns() {return(recvEqns_->getNumEqns());};
196 
197  std::vector<int>& localEqnNumbers() {return(recvEqns_->eqnNumbers());};
198  std::vector<fei::CSVec*>& localEqns(){return(recvEqns_->eqns());};
199  std::vector<std::vector<double>*>* localRHSsPtr()
200  {return(recvEqns_->rhsCoefsPtr());};
201 
202  int addRemoteEqn(int eqnNumber, int destProc, const double* coefs,
203  const int* indices, int num);
204 
205  int addRemoteEqn(int eqnNumber, const double* coefs,
206  const int* indices, int num);
207 
208  int addRemoteEqns(fei::CSRMat& mat, bool onlyIndices);
209  int addRemoteRHS(fei::CSVec& vec, int rhsIndex);
210 
211  void setNumRHSs(int numRHSs);
212 
213  int addRemoteRHS(int eqnNumber, int destProc, int rhsIndex, double value);
214 
215  int addRemoteRHS(int eqnNumber, int rhsIndex, double value);
216 
217  void addRemoteIndices(int eqnNumber, int destProc, int* indices, int num);
218 
219  int getNumRemoteEqns() {return(sendEqns_->getNumEqns());};
220 
221  std::vector<int>& sendEqnNumbersPtr() {return(sendEqns_->eqnNumbers());};
222 
223  double* sendEqnSolnPtr() {return(sendEqnSoln_.size()>0? &sendEqnSoln_[0] : NULL);};
224 
225  void resetCoefs();
226 
227  int gatherSharedBCs(EqnBuffer& bcEqns);
228 
229  int exchangeRemEssBCs(int* essEqns, int numEssEqns, double* essAlpha,
230  double* essGamma, MPI_Comm comm,
231  std::ostream* dbgOut = NULL);
232 
233  int getNumRemEssBCEqns() {return(essBCEqns_->getNumEqns());};
234  std::vector<int>& remEssBCEqnNumbersPtr() {return(essBCEqns_->eqnNumbers());};
235  std::vector<fei::CSVec*>& remEssBCEqns() {return(essBCEqns_->eqns());};
236 
237  int exchangePtToBlkInfo(snl_fei::PointBlockMap& blkEqnMapper);
238 
239  bool newCoefData() {if (recvEqns_->newCoefData_>0) return(true);
240  else return(false);}
241  bool newRHSData() {if (recvEqns_->newRHSData_>0) return(true);
242  else return(false);}
243 
244  bool accumulate_;
245 
246  EqnBuffer* getRecvEqns() { return( recvEqns_ ); }
247  EqnBuffer* getSendEqns() { return( sendEqns_ ); }
248  ProcEqns* getRecvProcEqns() { return( recvProcEqns_ ); }
249  ProcEqns* getSendProcEqns() { return( sendProcEqns_ ); }
250 
251  private:
252  void deleteEssBCs();
253  int getSendProcNumber(int eqn);
254 
255  int consistencyCheck(const char* caller,
256  std::vector<int>& recvProcs,
257  std::vector<int>& recvProcTotalLengths,
258  std::vector<int>& sendProcs,
259  std::vector<int>& sendProcTotalLengths);
260 
261  int localProc_;
262 
263  ProcEqns* recvProcEqns_;
264 
265  bool exchangeIndicesCalled_; //whether or not the exchangeIndices function
266  //has been called yet.
267 
268  EqnBuffer* recvEqns_;
269 
270  std::vector<double> solnValues_; //solution values we'll need to return to the
271  //processors that contribute to our equations
272 
273  ProcEqns* sendProcEqns_;
274 
275  EqnBuffer* sendEqns_;
276 
277  std::vector<double> sendEqnSoln_;
278  //the solution values for the send equations. i.e.,
279  //we'll recv these solution values for the equations
280  //that we contributed to (sent) for other processors.
281 
282  EqnBuffer* essBCEqns_;
283 
284  MPI_Comm comm_;
285 };
286 
287 #endif
288 
std::vector< fei::CSVec * > & eqns()
EqnCommMgr(MPI_Comm comm, bool accumulate=true)
int mirrorProcEqns(ProcEqns &inProcEqns, ProcEqns &outProcEqns)
std::vector< int > & eqnNumbers()
EqnCommMgr & operator=(const EqnCommMgr &src)
size_t getNumSharingProcs()
std::vector< std::vector< double > * > * rhsCoefsPtr()
void addLocalEqn(int eqnNumber, int srcProc)
std::vector< int > & procsPtr()
size_t getNumOwnerProcs()
virtual ~EqnCommMgr()
size_t getNumProcs()
EqnCommMgr * deepCopy()
int mirrorProcEqnLengths(ProcEqns &inProcEqns, ProcEqns &outProcEqns)
int getNumEqns()