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   int gatherFromOverlap(bool accumulate);
00184 
00185   void setMatrixGraph(fei::SharedPtr<fei::MatrixGraph> matrixGraph);
00186 
00196   int copyPointRowsToBlockRow(int numPtRows,
00197                               int numPtCols,
00198                               const double*const* ptValues,
00199                               int numBlkCols,
00200                               const int* blkColDims,
00201                               double** blkValues);
00202 
00203   int convertPtToBlk(int numRows,
00204                        const int* rows,
00205                        int numCols,
00206                        const int* cols,
00207                        int* blkRows,
00208                        int* blkRowOffsets,
00209                        int* blkCols,
00210                        int* blkColOffsets);
00211 
00212   MPI_Comm getCommunicator() const { return( comm_ ); }
00213 
00214   const fei::SharedPtr<fei::VectorSpace> vecSpace() const { return( vecSpace_ ); }
00215   fei::SharedPtr<fei::VectorSpace> vecSpace() { return( vecSpace_ ); }
00216 
00217   std::vector<int>& globalOffsets() { return( globalOffsets_ ); }
00218   const std::vector<int>& globalOffsets() const { return( globalOffsets_ ); }
00219 
00220   int firstLocalOffset() const { return( firstLocalOffset_ ); }
00221   int lastLocalOffset() const  { return( lastLocalOffset_ ); }
00222 
00223   int numProcs() const { return( numProcs_ ); }
00224   int localProc() const { return( localProc_ ); }
00225 
00226   bool haveBlockMatrix() const { return( haveBlockMatrix_ ); }
00227   void setBlockMatrix(bool flag) {haveBlockMatrix_ = flag; }
00228 
00229   bool haveFEMatrix() const { return( haveFEMatrix_ ); }
00230   void setFEMatrix(bool flag) {haveFEMatrix_ = flag; }
00231 
00232   int getOwnerProc(int globalEqn) const;
00233 
00234   std::string name_;
00235 
00236   std::vector<int> work_indices_;
00237   std::vector<int> work_indices2_;
00238 
00239   std::vector<int> work_ints_;
00240 
00241   std::vector<double> work_data1D_;
00242   std::vector<const double*> work_data2D_;
00243 
00244  protected:
00245   fei::SharedPtr<fei::EqnComm> eqnComm_;
00246 
00247  private:
00248   fei::SharedPtr<fei::Vector> rhsVector_;
00249 
00250   MPI_Comm comm_;
00251 
00252   int localProc_, numProcs_;
00253 
00254   fei::SharedPtr<fei::VectorSpace> vecSpace_;
00255   fei::SharedPtr<fei::MatrixGraph> matrixGraph_;
00256 
00257   std::map<int,FillableMat*> remotelyOwned_;
00258   mutable FillableMat* remotelyOwned_last_requested_;
00259   std::vector<int> sendProcs_;
00260   std::vector<int> recvProcs_;
00261   bool sendRecvProcsNeedUpdated_;
00262   mutable int proc_last_requested_;
00263 
00264   bool haveBlockMatrix_;
00265   bool haveFEMatrix_;
00266 
00267   std::vector<int> globalOffsets_;
00268   int firstLocalOffset_, lastLocalOffset_;
00269 };//class Matrix_core
00270 }//namespace fei
00271 
00272 #endif
00273 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends