Epetra Package Browser (Single Doxygen Collection) Development
Epetra_FECrsMatrix.h
Go to the documentation of this file.
00001 /*
00002 //@HEADER
00003 // ************************************************************************
00004 //
00005 //               Epetra: Linear Algebra Services Package
00006 //                 Copyright 2011 Sandia Corporation
00007 //
00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009 // the U.S. Government retains certain rights in this software.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00039 //
00040 // ************************************************************************
00041 //@HEADER
00042 */
00043 
00044 #ifndef EPETRA_FECRSMATRIX_H
00045 #define EPETRA_FECRSMATRIX_H
00046 
00047 #include <Epetra_ConfigDefs.h>
00048 #include <Epetra_CrsMatrix.h>
00049 #include <Epetra_CombineMode.h>
00050 
00051 #include <vector>
00052 
00053 class Epetra_Map;
00054 class Epetra_IntSerialDenseVector;
00055 
00056 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00057 class Epetra_LongLongSerialDenseVector;
00058 #endif
00059 
00060 class Epetra_SerialDenseMatrix;
00061 class Epetra_FECrsGraph;
00062 
00120 class EPETRA_LIB_DLL_EXPORT Epetra_FECrsMatrix : public Epetra_CrsMatrix {
00121   public:
00123    Epetra_FECrsMatrix(Epetra_DataAccess CV,
00124           const Epetra_Map& RowMap,
00125           int* NumEntriesPerRow,
00126           bool ignoreNonLocalEntries=false);
00127 
00129    Epetra_FECrsMatrix(Epetra_DataAccess CV,
00130           const Epetra_Map& RowMap,
00131           int NumEntriesPerRow,
00132           bool ignoreNonLocalEntries=false);
00133 
00135    Epetra_FECrsMatrix(Epetra_DataAccess CV,
00136           const Epetra_Map& RowMap,
00137           const Epetra_Map& ColMap,
00138           int* NumEntriesPerRow,
00139           bool ignoreNonLocalEntries=false);
00140 
00142    Epetra_FECrsMatrix(Epetra_DataAccess CV,
00143           const Epetra_Map& RowMap,
00144           const Epetra_Map& ColMap,
00145           int NumEntriesPerRow,
00146           bool ignoreNonLocalEntries=false);
00147 
00149    Epetra_FECrsMatrix(Epetra_DataAccess CV,
00150           const Epetra_CrsGraph& Graph,
00151           bool ignoreNonLocalEntries=false);
00152 
00154    Epetra_FECrsMatrix(Epetra_DataAccess CV,
00155          const Epetra_FECrsGraph& Graph,
00156          bool ignoreNonLocalEntries=false);
00157 
00159    Epetra_FECrsMatrix(const Epetra_FECrsMatrix& src);
00160 
00162    virtual ~Epetra_FECrsMatrix();
00163 
00165    Epetra_FECrsMatrix& operator=(const Epetra_FECrsMatrix& src);
00166 
00167    enum { ROW_MAJOR = 0, COLUMN_MAJOR = 3 };
00168 
00169 #if !defined(EPETRA_NO_32BIT_GLOBAL_INDICES) || !defined(EPETRA_NO_64BIT_GLOBAL_INDICES)
00170    using Epetra_CrsMatrix::SumIntoGlobalValues;
00171    using Epetra_CrsMatrix::InsertGlobalValues;
00172    using Epetra_CrsMatrix::ReplaceGlobalValues;
00173 #endif
00174 
00176 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00177    int SumIntoGlobalValues(int GlobalRow, int NumEntries,
00178                            const double* Values, const int* Indices);
00179 #endif
00180 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00181    int SumIntoGlobalValues(long long GlobalRow, int NumEntries,
00182                            const double* Values, const long long* Indices);
00183 #endif
00184 
00186 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00187    int InsertGlobalValues(int GlobalRow, int NumEntries,
00188                            const double* Values, const int* Indices);
00189 #endif
00190 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00191    int InsertGlobalValues(long long GlobalRow, int NumEntries,
00192                            const double* Values, const long long* Indices);
00193 #endif
00194 
00196 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00197    int InsertGlobalValues(int GlobalRow, int NumEntries,
00198                            double* Values, int* Indices);
00199 #endif
00200 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00201    int InsertGlobalValues(long long GlobalRow, int NumEntries,
00202                            double* Values, long long* Indices);
00203 #endif
00204 
00206 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00207    int ReplaceGlobalValues(int GlobalRow, int NumEntries,
00208                            const double* Values, const int* Indices);
00209 #endif
00210 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00211    int ReplaceGlobalValues(long long GlobalRow, int NumEntries,
00212                            const double* Values, const long long* Indices);
00213 #endif
00214 
00230 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00231    int SumIntoGlobalValues(int numIndices, const int* indices,
00232                            const double* values,
00233                            int format=Epetra_FECrsMatrix::COLUMN_MAJOR);
00234 #endif
00235 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00236    int SumIntoGlobalValues(int numIndices, const long long* indices,
00237                            const double* values,
00238                            int format=Epetra_FECrsMatrix::COLUMN_MAJOR);
00239 #endif
00240 
00257 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00258    int SumIntoGlobalValues(int numRows, const int* rows,
00259                            int numCols, const int* cols,
00260                            const double* values,
00261                            int format=Epetra_FECrsMatrix::COLUMN_MAJOR);
00262 #endif
00263 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00264    int SumIntoGlobalValues(int numRows, const long long* rows,
00265                            int numCols, const long long* cols,
00266                            const double* values,
00267                            int format=Epetra_FECrsMatrix::COLUMN_MAJOR);
00268 #endif
00269 
00284 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00285    int SumIntoGlobalValues(int numIndices, const int* indices,
00286                            const double* const* values,
00287                            int format=Epetra_FECrsMatrix::ROW_MAJOR);
00288 #endif
00289 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00290    int SumIntoGlobalValues(int numIndices, const long long* indices,
00291                            const double* const* values,
00292                            int format=Epetra_FECrsMatrix::ROW_MAJOR);
00293 #endif
00294 
00310 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00311    int SumIntoGlobalValues(int numRows, const int* rows,
00312                      int numCols, const int* cols,
00313                            const double* const* values,
00314                            int format=Epetra_FECrsMatrix::ROW_MAJOR);
00315 #endif
00316 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00317    int SumIntoGlobalValues(int numRows, const long long* rows,
00318                      int numCols, const long long* cols,
00319                            const double* const* values,
00320                            int format=Epetra_FECrsMatrix::ROW_MAJOR);
00321 #endif
00322 
00337 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00338    int InsertGlobalValues(int numIndices, const int* indices,
00339                            const double* values,
00340                            int format=Epetra_FECrsMatrix::COLUMN_MAJOR);
00341 #endif
00342 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00343    int InsertGlobalValues(int numIndices, const long long* indices,
00344                            const double* values,
00345                            int format=Epetra_FECrsMatrix::COLUMN_MAJOR);
00346 #endif
00347 
00363 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00364    int InsertGlobalValues(int numRows, const int* rows,
00365                            int numCols, const int* cols,
00366                            const double* values,
00367                            int format=Epetra_FECrsMatrix::COLUMN_MAJOR);
00368 #endif
00369 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00370    int InsertGlobalValues(int numRows, const long long* rows,
00371                            int numCols, const long long* cols,
00372                            const double* values,
00373                            int format=Epetra_FECrsMatrix::COLUMN_MAJOR);
00374 #endif
00375 
00389 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00390    int InsertGlobalValues(int numIndices, const int* indices,
00391                            const double* const* values,
00392                            int format=Epetra_FECrsMatrix::ROW_MAJOR);
00393 #endif
00394 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00395    int InsertGlobalValues(int numIndices, const long long* indices,
00396                            const double* const* values,
00397                            int format=Epetra_FECrsMatrix::ROW_MAJOR);
00398 #endif
00399 
00414 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00415    int InsertGlobalValues(int numRows, const int* rows,
00416                      int numCols, const int* cols,
00417                            const double* const* values,
00418                            int format=Epetra_FECrsMatrix::ROW_MAJOR);
00419 #endif
00420 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00421    int InsertGlobalValues(int numRows, const long long* rows,
00422                      int numCols, const long long* cols,
00423                            const double* const* values,
00424                            int format=Epetra_FECrsMatrix::ROW_MAJOR);
00425 #endif
00426 
00442 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00443    int ReplaceGlobalValues(int numIndices, const int* indices,
00444                            const double* values,
00445                            int format=Epetra_FECrsMatrix::COLUMN_MAJOR);
00446 #endif
00447 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00448    int ReplaceGlobalValues(int numIndices, const long long* indices,
00449                            const double* values,
00450                            int format=Epetra_FECrsMatrix::COLUMN_MAJOR);
00451 #endif
00452 
00470 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00471    int ReplaceGlobalValues(int numRows, const int* rows,
00472                            int numCols, const int* cols,
00473                            const double* values,
00474                            int format=Epetra_FECrsMatrix::COLUMN_MAJOR);
00475 #endif
00476 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00477    int ReplaceGlobalValues(int numRows, const long long* rows,
00478                            int numCols, const long long* cols,
00479                            const double* values,
00480                            int format=Epetra_FECrsMatrix::COLUMN_MAJOR);
00481 #endif
00482 
00497 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00498    int ReplaceGlobalValues(int numIndices, const int* indices,
00499                            const double* const* values,
00500                            int format=Epetra_FECrsMatrix::ROW_MAJOR);
00501 #endif
00502 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00503    int ReplaceGlobalValues(int numIndices, const long long* indices,
00504                            const double* const* values,
00505                            int format=Epetra_FECrsMatrix::ROW_MAJOR);
00506 #endif
00507 
00523 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00524    int ReplaceGlobalValues(int numRows, const int* rows,
00525                            int numCols, const int* cols,
00526                            const double* const* values,
00527                            int format=Epetra_FECrsMatrix::ROW_MAJOR);
00528 #endif
00529 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00530    int ReplaceGlobalValues(int numRows, const long long* rows,
00531                            int numCols, const long long* cols,
00532                            const double* const* values,
00533                            int format=Epetra_FECrsMatrix::ROW_MAJOR);
00534 #endif
00535 
00546 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00547    int SumIntoGlobalValues(const Epetra_IntSerialDenseVector& indices,
00548          const Epetra_SerialDenseMatrix& values,
00549          int format=Epetra_FECrsMatrix::COLUMN_MAJOR);
00550 #endif
00551 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00552    int SumIntoGlobalValues(const Epetra_LongLongSerialDenseVector& indices,
00553          const Epetra_SerialDenseMatrix& values,
00554          int format=Epetra_FECrsMatrix::COLUMN_MAJOR);
00555 #endif
00556 
00571 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00572    int SumIntoGlobalValues(const Epetra_IntSerialDenseVector& rows,
00573          const Epetra_IntSerialDenseVector& cols,
00574          const Epetra_SerialDenseMatrix& values,
00575          int format=Epetra_FECrsMatrix::COLUMN_MAJOR);
00576 #endif
00577 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00578    int SumIntoGlobalValues(const Epetra_LongLongSerialDenseVector& rows,
00579          const Epetra_LongLongSerialDenseVector& cols,
00580          const Epetra_SerialDenseMatrix& values,
00581          int format=Epetra_FECrsMatrix::COLUMN_MAJOR);
00582 #endif
00583 
00594 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00595    int InsertGlobalValues(const Epetra_IntSerialDenseVector& indices,
00596          const Epetra_SerialDenseMatrix& values,
00597          int format=Epetra_FECrsMatrix::COLUMN_MAJOR);
00598 #endif
00599 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00600    int InsertGlobalValues(const Epetra_LongLongSerialDenseVector& indices,
00601          const Epetra_SerialDenseMatrix& values,
00602          int format=Epetra_FECrsMatrix::COLUMN_MAJOR);
00603 #endif
00604 
00619 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00620    int InsertGlobalValues(const Epetra_IntSerialDenseVector& rows,
00621          const Epetra_IntSerialDenseVector& cols,
00622          const Epetra_SerialDenseMatrix& values,
00623          int format=Epetra_FECrsMatrix::COLUMN_MAJOR);
00624 #endif
00625 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00626    int InsertGlobalValues(const Epetra_LongLongSerialDenseVector& rows,
00627          const Epetra_LongLongSerialDenseVector& cols,
00628          const Epetra_SerialDenseMatrix& values,
00629          int format=Epetra_FECrsMatrix::COLUMN_MAJOR);
00630 #endif
00631 
00643 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00644    int ReplaceGlobalValues(const Epetra_IntSerialDenseVector& indices,
00645          const Epetra_SerialDenseMatrix& values,
00646          int format=Epetra_FECrsMatrix::COLUMN_MAJOR);
00647 #endif
00648 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00649    int ReplaceGlobalValues(const Epetra_LongLongSerialDenseVector& indices,
00650          const Epetra_SerialDenseMatrix& values,
00651          int format=Epetra_FECrsMatrix::COLUMN_MAJOR);
00652 #endif
00653 
00668 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00669    int ReplaceGlobalValues(const Epetra_IntSerialDenseVector& rows,
00670          const Epetra_IntSerialDenseVector& cols,
00671          const Epetra_SerialDenseMatrix& values,
00672          int format=Epetra_FECrsMatrix::COLUMN_MAJOR);
00673 #endif
00674 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00675    int ReplaceGlobalValues(const Epetra_LongLongSerialDenseVector& rows,
00676          const Epetra_LongLongSerialDenseVector& cols,
00677          const Epetra_SerialDenseMatrix& values,
00678          int format=Epetra_FECrsMatrix::COLUMN_MAJOR);
00679 #endif
00680 
00702    int GlobalAssemble(bool callFillComplete=true,
00703                       Epetra_CombineMode combineMode=Add,
00704                       bool save_off_and_reuse_map_exporter=false);
00705 
00731    int GlobalAssemble(const Epetra_Map& domain_map,
00732                       const Epetra_Map& range_map,
00733                       bool callFillComplete=true,
00734                       Epetra_CombineMode combineMode=Add,
00735                       bool save_off_and_reuse_map_exporter=false);
00736 
00740    void setIgnoreNonLocalEntries(bool flag) {
00741      ignoreNonLocalEntries_ = flag;
00742    }
00743 
00744   private:
00745    void DeleteMemory();
00746 
00747    enum {SUMINTO = 0, REPLACE = 1, INSERT = 2};
00748 
00749    template<typename int_type>
00750    int InputGlobalValues(int numRows, const int_type* rows,
00751                          int numCols, const int_type* cols,
00752                          const double* const* values,
00753                          int format,
00754                          int mode);
00755 
00756    template<typename int_type>
00757    int InputGlobalValues(int numRows, const int_type* rows,
00758                          int numCols, const int_type* cols,
00759                          const double* values,
00760                          int format,
00761                          int mode);
00762 
00763    template<typename int_type>
00764    int InputNonlocalGlobalValues(int_type row,
00765          int numCols, const int_type* cols,
00766          const double* values,
00767          int mode);
00768 
00769   template<typename int_type>
00770   int InputGlobalValues_RowMajor(
00771             int numRows, const int_type* rows,
00772             int numCols, const int_type* cols,
00773             const double* values,
00774             int mode);
00775 
00776    template<typename int_type>
00777    int InsertNonlocalRow(int_type row, typename std::vector<int_type>::iterator offset);
00778 
00779    template<typename int_type>
00780    int InputNonlocalValue(int rowoffset,
00781         int_type col, double value,
00782         int mode);
00783 
00784    long long myFirstRow_;
00785    int myNumRows_;
00786 
00787    bool ignoreNonLocalEntries_;
00788 
00789 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00790    std::vector<int> nonlocalRows_int_;
00791    std::vector<std::vector<int> > nonlocalCols_int_;
00792 #endif
00793 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00794    std::vector<long long> nonlocalRows_LL_;
00795    std::vector<std::vector<long long> > nonlocalCols_LL_;
00796 #endif
00797 
00798    template<typename int_type> std::vector<int_type>& nonlocalRows();
00799    template<typename int_type> std::vector<std::vector<int_type> >& nonlocalCols();
00800 
00801    std::vector<std::vector<double> > nonlocalCoefs_;
00802 
00803    //IMPORTANT NOTE: The use of class-member work-data arrays is
00804    //**NOT** thread-safe.
00805    std::vector<double> workData_;
00806    std::vector<const double*> workData2d_;
00807    int workDataLength_;
00808 
00809    bool useNonlocalMatrix_;
00810    Epetra_CrsMatrix* nonlocalMatrix_;
00811 
00812    Epetra_Map* sourceMap_;
00813    Epetra_Map* colMap_;
00814    Epetra_Export* exporter_;
00815    Epetra_CrsMatrix* tempMat_;
00816 
00817    template<typename int_type>
00818    int SumIntoGlobalValues(int_type GlobalRow, int NumEntries, const double* values, const int_type* Indices);
00819 
00820    template<typename int_type>
00821    int GlobalAssemble(const Epetra_Map& domain_map,
00822                       const Epetra_Map& range_map,
00823                       bool callFillComplete=true,
00824                       Epetra_CombineMode combineMode=Add,
00825                       bool save_off_and_reuse_map_exporter=false);
00826 
00827 };//class Epetra_FECrsMatrix
00828 
00829 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00830 template<> inline std::vector<int>& Epetra_FECrsMatrix::nonlocalRows<int>()
00831 {
00832   return nonlocalRows_int_;
00833 }
00834 #endif
00835 
00836 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00837 template<> inline std::vector<long long>& Epetra_FECrsMatrix::nonlocalRows<long long>()
00838 {
00839   return nonlocalRows_LL_;
00840 }
00841 #endif
00842 
00843 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00844 template<> inline std::vector<std::vector<int> >& Epetra_FECrsMatrix::nonlocalCols<int>()
00845 {
00846   return nonlocalCols_int_;
00847 }
00848 #endif
00849 
00850 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00851 template<> inline std::vector<std::vector<long long> >& Epetra_FECrsMatrix::nonlocalCols<long long>()
00852 {
00853   return nonlocalCols_LL_;
00854 }
00855 #endif
00856 
00857 
00858 #endif /* EPETRA_FECRSMATRIX_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines