FEI Version of the Day
fei_EqnCommMgr.hpp
00001 /*
00002 // @HEADER
00003 // ************************************************************************
00004 //             FEI: Finite Element Interface to Linear Solvers
00005 //                  Copyright (2005) Sandia Corporation.
00006 //
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the
00008 // U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Alan Williams (william@sandia.gov) 
00038 //
00039 // ************************************************************************
00040 // @HEADER
00041 */
00042 
00043 #ifndef _fei_EqnCommMgr_hpp_
00044 #define _fei_EqnCommMgr_hpp_
00045 
00046 
00047 #include "fei_fwd.hpp"
00048 #include "fei_mpi.h"
00049 
00050 #include "snl_fei_PointBlockMap.hpp"
00051 
00052 #include <fei_CSRMat.hpp>
00053 #include <fei_CSVec.hpp>
00054 #include <fei_CommUtils.hpp>
00055 #include "fei_ProcEqns.hpp"
00056 #include "fei_EqnBuffer.hpp"
00057 
00139 class EqnCommMgr {
00140  public:
00144    EqnCommMgr(MPI_Comm comm, bool accumulate = true);
00145 
00147    EqnCommMgr(const EqnCommMgr& src);
00148 
00150    EqnCommMgr& operator=(const EqnCommMgr& src);
00151 
00153    virtual ~EqnCommMgr();
00154 
00156    EqnCommMgr* deepCopy();
00157 
00161    size_t getNumSharingProcs() {return(recvProcEqns_->getNumProcs());};
00162    std::vector<int>& sharingProcsPtr() {return(recvProcEqns_->procsPtr());};
00163 
00167    size_t getNumOwnerProcs() {return(sendProcEqns_->getNumProcs());};
00168    std::vector<int>& ownerProcsPtr() {return(sendProcEqns_->procsPtr());};
00169 
00171    void addLocalEqn(int eqnNumber, int srcProc);
00172 
00173    void addSolnValues(int* eqnNumbers, double* values, int num);
00174 
00175 #ifdef FEI_HAVE_IOSFWD
00176    int exchangeIndices(std::ostream* dbgOut=NULL);
00177    int exchangeEqns(std::ostream* dbgOut=NULL);
00178 #else
00179    int exchangeIndices(ostream* dbgOut=NULL);
00180    int exchangeEqns(ostream* dbgOut=NULL);
00181 #endif
00182 
00183    void exchangeSoln();
00184 
00208    int mirrorProcEqns(ProcEqns& inProcEqns, ProcEqns& outProcEqns);
00209 
00222    int mirrorProcEqnLengths(ProcEqns& inProcEqns,
00223           ProcEqns& outProcEqns);
00224 
00225 
00226    static int exchangeEqnBuffers(MPI_Comm comm, ProcEqns* sendProcEqns,
00227          EqnBuffer* sendEqns, ProcEqns* recvProcEqns,
00228          EqnBuffer* recvEqns, bool accumulate);
00229 
00230    int getNumLocalEqns() {return(recvEqns_->getNumEqns());};
00231 
00232    std::vector<int>& localEqnNumbers() {return(recvEqns_->eqnNumbers());};
00233    std::vector<fei::CSVec*>& localEqns(){return(recvEqns_->eqns());};
00234    std::vector<std::vector<double>*>* localRHSsPtr()
00235      {return(recvEqns_->rhsCoefsPtr());};
00236 
00237    int addRemoteEqn(int eqnNumber, int destProc, const double* coefs,
00238                    const int* indices, int num);
00239 
00240    int addRemoteEqn(int eqnNumber, const double* coefs,
00241         const int* indices, int num);
00242 
00243    int addRemoteEqns(fei::CSRMat& mat, bool onlyIndices);
00244    int addRemoteRHS(fei::CSVec& vec, int rhsIndex);
00245 
00246    void setNumRHSs(int numRHSs);
00247 
00248    int addRemoteRHS(int eqnNumber, int destProc, int rhsIndex, double value);
00249 
00250    int addRemoteRHS(int eqnNumber, int rhsIndex, double value);
00251 
00252    void addRemoteIndices(int eqnNumber, int destProc, int* indices, int num);
00253 
00254    int getNumRemoteEqns() {return(sendEqns_->getNumEqns());};
00255 
00256    std::vector<int>& sendEqnNumbersPtr() {return(sendEqns_->eqnNumbers());};
00257 
00258    double* sendEqnSolnPtr() {return(sendEqnSoln_.size()>0? &sendEqnSoln_[0] : NULL);};
00259 
00260    void resetCoefs();
00261 
00262    int gatherSharedBCs(EqnBuffer& bcEqns);
00263 
00264    int exchangeRemEssBCs(int* essEqns, int numEssEqns, double* essAlpha,
00265        double* essGamma, MPI_Comm comm,
00266        std::ostream* dbgOut = NULL);
00267 
00268    int getNumRemEssBCEqns() {return(essBCEqns_->getNumEqns());};
00269    std::vector<int>& remEssBCEqnNumbersPtr() {return(essBCEqns_->eqnNumbers());};
00270    std::vector<fei::CSVec*>& remEssBCEqns() {return(essBCEqns_->eqns());};
00271 
00272    int exchangePtToBlkInfo(snl_fei::PointBlockMap& blkEqnMapper);
00273 
00274    bool newCoefData() {if (recvEqns_->newCoefData_>0) return(true);
00275                        else return(false);}
00276    bool newRHSData() {if (recvEqns_->newRHSData_>0) return(true);
00277                       else return(false);}
00278 
00279    bool accumulate_;
00280 
00281    EqnBuffer* getRecvEqns() { return( recvEqns_ ); }
00282    EqnBuffer* getSendEqns() { return( sendEqns_ ); }
00283    ProcEqns* getRecvProcEqns() { return( recvProcEqns_ ); }
00284    ProcEqns* getSendProcEqns() { return( sendProcEqns_ ); }
00285 
00286  private:
00287    void deleteEssBCs();
00288    int getSendProcNumber(int eqn);
00289 
00290    int consistencyCheck(const char* caller,
00291       std::vector<int>& recvProcs,
00292       std::vector<int>& recvProcTotalLengths,
00293       std::vector<int>& sendProcs,
00294       std::vector<int>& sendProcTotalLengths);
00295 
00296    int localProc_;
00297 
00298    ProcEqns* recvProcEqns_;
00299 
00300    bool exchangeIndicesCalled_; //whether or not the exchangeIndices function
00301                                 //has been called yet.
00302 
00303    EqnBuffer* recvEqns_;
00304 
00305    std::vector<double> solnValues_; //solution values we'll need to return to the
00306                               //processors that contribute to our equations
00307 
00308    ProcEqns* sendProcEqns_;
00309 
00310    EqnBuffer* sendEqns_;
00311 
00312    std::vector<double> sendEqnSoln_; 
00313                           //the solution values for the send equations. i.e.,
00314                           //we'll recv these solution values for the equations
00315                           //that we contributed to (sent) for other processors.
00316 
00317    EqnBuffer* essBCEqns_;
00318 
00319    MPI_Comm comm_;
00320 };
00321 
00322 #endif
00323 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends