FEI Version of the Day
fei_Matrix_core.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_Matrix_core_hpp_
00044 #define _fei_Matrix_core_hpp_
00045 
00046 
00047 #include <fei_macros.hpp>
00048 #include <fei_mpi.h>
00049 #include <fei_EqnComm.hpp>
00050 #include <fei_fwd.hpp>
00051 #include <fei_Vector.hpp>
00052 #include <fei_CommUtils.hpp>
00053 #include <fei_FillableMat.hpp>
00054 #include <fei_MatrixGraph.hpp>
00055 #include <fei_Logger.hpp>
00056 
00057 #include <vector>
00058 
00059 namespace fei {
00060 class Matrix_core : protected fei::Logger {
00061  public:
00062 
00063   Matrix_core(fei::SharedPtr<fei::MatrixGraph> matrixGraph, int numLocalEqns);
00064 
00065   virtual ~Matrix_core();
00066 
00067   virtual int giveToMatrix(int numRows, const int* rows,
00068                            int numCols, const int* cols,
00069                            const double* const* values,
00070                            bool sumInto,
00071                            int format) = 0;
00072 
00097   static void copyTransposeToWorkArrays(int numRows, int numCols,
00098                                        const double*const* values,
00099                                        std::vector<double>& work_1D,
00100                                        std::vector<const double*>& work_2D);
00101 
00108   void setRHS(fei::SharedPtr<fei::Vector> rhsvector);
00109 
00114   void setSlaveInfo(fei::SharedPtr<fei::MatrixGraph> matrixGraph);
00115 
00116   fei::SharedPtr<fei::MatrixGraph> getMatrixGraph() const { return( matrixGraph_ ); }
00117 
00118   const FillableMat* getRemotelyOwnedMatrix(int proc) const
00119   {
00120     if (proc_last_requested_ == proc) {
00121       return remotelyOwned_last_requested_;
00122     }
00123     FillableMat* remote_mat = NULL;
00124     std::map<int,FillableMat*>::const_iterator it = remotelyOwned_.find(proc);
00125     if (it != remotelyOwned_.end()) {
00126       remote_mat = it->second;
00127       remotelyOwned_last_requested_ = remote_mat;
00128       proc_last_requested_ = proc;
00129     }
00130     return( remote_mat );
00131   }
00132 
00133   FillableMat* getRemotelyOwnedMatrix(int proc)
00134   {
00135     if (proc_last_requested_ == proc) {
00136       return remotelyOwned_last_requested_;
00137     }
00138     proc_last_requested_ = proc;
00139     FillableMat* remote_mat = NULL;
00140     std::map<int,FillableMat*>::iterator it = remotelyOwned_.find(proc);
00141     if (it == remotelyOwned_.end()) {
00142       remote_mat = new FillableMat;
00143       remotelyOwned_.insert(std::make_pair(proc, remote_mat));
00144     }
00145     else {
00146       remote_mat = it->second;
00147     }
00148     remotelyOwned_last_requested_ = remote_mat;
00149     return( remote_mat );
00150   }
00151 
00152   std::map<int,FillableMat*>& getRemotelyOwnedMatrices();
00153 
00154   void putScalar_remotelyOwned(double scalar);
00155 
00156   void setEqnComm(fei::SharedPtr<fei::EqnComm> eqnComm);
00157 
00158  protected:
00159   void parameters(const fei::ParameterSet& paramset);
00160 
00161   virtual int giveToUnderlyingMatrix(int numRows, const int* rows,
00162                                      int numCols, const int* cols,
00163                                      const double* const* values,
00164                                      bool sumInto,
00165                                      int format) = 0;
00166 
00167   virtual int giveToBlockMatrix(int numRows, const int* rows,
00168                                           int numCols, const int* cols,
00169                                           const double* const* values,
00170                                           bool sumInto) = 0;
00171 
00172   virtual int giveToUnderlyingBlockMatrix(int row,
00173                                           int rowDim,
00174                                           int numCols,
00175                                           const int* cols,
00176                                           const int* LDAs,
00177                                           const int* colDims,
00178                                           const double* const* values,
00179                                           bool sumInto) = 0;
00180 
00181   void setName(const char* name);
00182 
00183   void setCommSizes();
00184   int gatherFromOverlap(bool accumulate);
00185 
00186   void setMatrixGraph(fei::SharedPtr<fei::MatrixGraph> matrixGraph);
00187 
00197   int copyPointRowsToBlockRow(int numPtRows,
00198                               int numPtCols,
00199                               const double*const* ptValues,
00200                               int numBlkCols,
00201                               const int* blkColDims,
00202                               double** blkValues);
00203 
00204   int convertPtToBlk(int numRows,
00205                        const int* rows,
00206                        int numCols,
00207                        const int* cols,
00208                        int* blkRows,
00209                        int* blkRowOffsets,
00210                        int* blkCols,
00211                        int* blkColOffsets);
00212 
00213   MPI_Comm getCommunicator() const { return( comm_ ); }
00214 
00215   const fei::SharedPtr<fei::VectorSpace> vecSpace() const { return( vecSpace_ ); }
00216   fei::SharedPtr<fei::VectorSpace> vecSpace() { return( vecSpace_ ); }
00217 
00218   std::vector<int>& globalOffsets() { return( globalOffsets_ ); }
00219   const std::vector<int>& globalOffsets() const { return( globalOffsets_ ); }
00220 
00221   int firstLocalOffset() const { return( firstLocalOffset_ ); }
00222   int lastLocalOffset() const  { return( lastLocalOffset_ ); }
00223 
00224   int numProcs() const { return( numProcs_ ); }
00225   int localProc() const { return( localProc_ ); }
00226 
00227   bool haveBlockMatrix() const { return( haveBlockMatrix_ ); }
00228   void setBlockMatrix(bool flag) {haveBlockMatrix_ = flag; }
00229 
00230   bool haveFEMatrix() const { return( haveFEMatrix_ ); }
00231   void setFEMatrix(bool flag) {haveFEMatrix_ = flag; }
00232 
00233   int getOwnerProc(int globalEqn) const;
00234 
00235   std::string name_;
00236 
00237   std::vector<int> work_indices_;
00238   std::vector<int> work_indices2_;
00239 
00240   std::vector<int> work_ints_;
00241 
00242   std::vector<double> work_data1D_;
00243   std::vector<const double*> work_data2D_;
00244 
00245  protected:
00246   fei::SharedPtr<fei::EqnComm> eqnComm_;
00247 
00248  private:
00249   fei::SharedPtr<fei::Vector> rhsVector_;
00250 
00251   MPI_Comm comm_;
00252 
00253   int localProc_, numProcs_;
00254 
00255   fei::SharedPtr<fei::VectorSpace> vecSpace_;
00256   fei::SharedPtr<fei::MatrixGraph> matrixGraph_;
00257 
00258   std::map<int,FillableMat*> remotelyOwned_;
00259   mutable FillableMat* remotelyOwned_last_requested_;
00260   std::vector<int> sendProcs_;
00261   std::vector<int> recvProcs_;
00262   std::vector<std::vector<char> > recv_chars_;
00263   std::vector<std::vector<char> > send_chars_;
00264   bool sendRecvProcsNeedUpdated_;
00265   mutable int proc_last_requested_;
00266 
00267   bool haveBlockMatrix_;
00268   bool haveFEMatrix_;
00269 
00270   std::vector<int> globalOffsets_;
00271   int firstLocalOffset_, lastLocalOffset_;
00272 };//class Matrix_core
00273 }//namespace fei
00274 
00275 #endif
00276 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends