FEI Version of the Day
fei_MatrixGraph_Impl2.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 
00044 #ifndef _fei_MatrixGraph_Impl2_hpp_
00045 #define _fei_MatrixGraph_Impl2_hpp_
00046 
00047 #include <fei_macros.hpp>
00048 #include <fei_SharedPtr.hpp>
00049 #include <fei_VectorSpace.hpp>
00050 #include <fei_Reducer.hpp>
00051 #include <fei_Graph.hpp>
00052 #include <snl_fei_Constraint.hpp>
00053 #include <fei_Record.hpp>
00054 #include <fei_Logger.hpp>
00055 #include <fei_SparseRowGraph.hpp>
00056 #include <fei_MatrixGraph.hpp>
00057 
00058 #include <vector>
00059 #include <map>
00060 
00061 namespace fei {
00062   class ConnectivityBlock;
00063   class Pattern;
00064 
00068 class MatrixGraph_Impl2 : public fei::MatrixGraph, private fei::Logger {
00069  public:
00071   class Factory {
00072   public:
00074     virtual ~Factory(){}
00075 
00080     virtual fei::SharedPtr<fei::MatrixGraph>
00081                  createMatrixGraph(fei::SharedPtr<fei::VectorSpace> rowSpace,
00082                                    fei::SharedPtr<fei::VectorSpace> columnSpace,
00083                                    const char* name);
00084   };
00085 
00091   MatrixGraph_Impl2(fei::SharedPtr<fei::VectorSpace> rowSpace,
00092               fei::SharedPtr<fei::VectorSpace> colSpace,
00093               const char* name = NULL);
00094 
00096   virtual ~MatrixGraph_Impl2();
00097 
00105   void setParameters(const fei::ParameterSet& params);
00106 
00113   void setRowSpace(fei::SharedPtr<fei::VectorSpace> rowSpace);
00114 
00118   fei::SharedPtr<fei::VectorSpace> getRowSpace();
00119 
00126   void setColumnSpace(fei::SharedPtr<fei::VectorSpace> columnSpace);
00127 
00131   fei::SharedPtr<fei::VectorSpace> getColSpace();
00132 
00152   int definePattern(int numIDs,
00153                     int idType);
00154 
00175   int definePattern(int numIDs,
00176                     int idType,
00177                     int fieldID);
00178 
00202    int definePattern(int numIDs,
00203                      int idType,
00204                      const int* numFieldsPerID,
00205                      const int* fieldIDs);
00206 
00229    int definePattern(int numIDs,
00230                      const int* idTypes,
00231                      const int* numFieldsPerID,
00232                      const int* fieldIDs);
00233 
00256    int initConnectivityBlock(int blockID,
00257                              int numConnectivityLists,
00258                              int patternID,
00259                              bool diagonal=false);
00260 
00283    int initConnectivityBlock(int numConnectivityLists,
00284                              int patternID,
00285                              bool diagonal=false);
00286 
00307    int initConnectivityBlock(int blockID,
00308                              int numConnectivityLists,
00309                              int rowPatternID,
00310                              int colPatternID);
00311 
00324    int initConnectivity(int blockID,
00325                         int connectivityID,
00326                         const int* connectedIdentifiers);
00327 
00342    int initConnectivity(int blockID,
00343                         int connectivityID,
00344                         const int* rowConnectedIdentifiers,
00345                         const int* colConnectedIdentifiers);
00346 
00358    int initConnectivity(int patternID,
00359                         const int* connectedIdentifiers);
00360 
00375    int initConnectivity(int rowPatternID,
00376                         const int* rowConnectedIdentifiers,
00377                         int colPatternID,
00378                         const int* colConnectedIdentifiers);
00379 
00395    int initConnectivity(int idType,
00396                         int numRows,
00397                         const int* rowIDs,
00398                         const int* rowOffsets,
00399                         const int* packedColumnIDs);
00400 
00418    int initConnectivity(int idType,
00419                         int fieldID,
00420                         int numRows,
00421                         const int* rowIDs,
00422                         const int* rowOffsets,
00423                         const int* packedColumnIDs);
00424 
00439    int initConnectivity(int idType,
00440                         int numRows,
00441                         const int* rowIDs,
00442                         const int* rowLengths,
00443                         const int*const* columnIDs);
00444 
00447    int initLagrangeConstraint(int constraintID,
00448                               int constraintIDType,
00449                               int numIDs,
00450                               const int* idTypes,
00451                               const int* IDs,
00452                               const int* fieldIDs);
00453 
00456    int initPenaltyConstraint(int constraintID,
00457                              int constraintIDType,
00458                              int numIDs,
00459                              const int* idTypes,
00460                              const int* IDs,
00461                              const int* fieldIDs);
00462 
00465    int initSlaveConstraint(int numIDs,
00466                            const int* idTypes,
00467                            const int* IDs,
00468                            const int* fieldIDs,
00469                            int offsetOfSlave,
00470                            int offsetIntoSlaveField,
00471                            const double* weights,
00472                            double rhsValue);
00473 
00474    bool newSlaveData();
00475 
00478    bool hasSlaveDof(int ID, int idType);
00479 
00484    int initComplete();
00485 
00497    fei::SharedPtr<fei::SparseRowGraph>
00498      createGraph(bool blockEntryGraph,
00499                  bool localRowGraph_includeSharedRows=false);
00500 
00504    int compareStructure(const fei::MatrixGraph& matrixGraph,
00505                         bool& equivalent) const;
00506 
00508    int getNumConnectivityBlocks() const;
00509 
00511    std::map<int,fei::ConnectivityBlock*>& getConnectivityBlocks();
00512 
00514    int getConnectivityBlockIDs(std::vector<int>& blockIDs) const;
00515 
00518    int getNumIDsPerConnectivityList(int blockID) const;
00519 
00523    int getConnectivityNumIndices(int blockID) const;
00524 
00529    int getConnectivityNumIndices(int blockID,
00530                                  int& numRowIndices,
00531                                  int& numColIndices);
00532 
00535    int getConnectivityIndices(int blockID,
00536                               int connectivityID,
00537                               int indicesAllocLen,
00538                               int* indices,
00539                               int& numIndices);
00540 
00544    int getConnectivityIndices(int blockID,
00545                               int connectivityID,
00546                               int rowIndicesAllocLen,
00547                               int* rowIndices,
00548                               int& numRowIndices,
00549                               int colIndicesAllocLen,
00550                               int* colIndices,
00551                               int& numColIndices);
00552 
00555    int getPatternNumIndices(int patternID,
00556                             int& numIndices);
00557 
00560    int getPatternIndices(int patternID,
00561                          const int* IDs,
00562                          std::vector<int>& indices);
00563 
00565    int getLocalNumLagrangeConstraints() const;
00566 
00569    int getGlobalNumSlaveConstraints() const;
00570 
00574    ConstraintType* getLagrangeConstraint(int constraintID);
00575 
00579    std::map<int, ConstraintType* >& getLagrangeConstraints();
00580 
00584    ConstraintType* getPenaltyConstraint(int constraintID);
00585 
00589    ConstraintType* getSlaveConstraint(int constraintID);
00590 
00594    int getConstraintConnectivityIndices(ConstraintType* cr,
00595                                         std::vector<int>& globalIndices);
00596 
00600    const fei::ConnectivityBlock* getConnectivityBlock(int blockID) const;
00601 
00605    fei::ConnectivityBlock* getConnectivityBlock(int blockID);
00606 
00608    void setIndicesMode(int mode);
00609 
00611    fei::SharedPtr<FillableMat> getSlaveDependencyMatrix();
00612 
00616    fei::Pattern* getPattern(int patternID);
00617 
00619    int createSlaveMatrices();
00620 
00622    fei::SharedPtr<fei::Reducer> getReducer();
00623 
00625    fei::SharedPtr<fei::SparseRowGraph> getRemotelyOwnedGraphRows();
00626 
00628    void getConstrainedIndices(std::vector<int>& crindices) const;
00629 
00630  private:
00631    int createAlgebraicGraph(bool blockEntryGraph,
00632                             fei::Graph* graph,
00633                             bool gatherFromOverlap);
00634 
00635    int addBlockToGraph_multiField_symmetric(fei::Graph* graph,
00636                                             fei::ConnectivityBlock* cblock);
00637    int addBlockToGraph_multiField_nonsymmetric(fei::Graph* graph,
00638                                             fei::ConnectivityBlock* cblock);
00639    int addBlockToGraph_singleField_symmetric(fei::Graph* graph,
00640                                              fei::ConnectivityBlock* cblock);
00641    int addBlockToGraph_singleField_nonsymmetric(fei::Graph* graph,
00642                                              fei::ConnectivityBlock* cblock);
00643    int addBlockToGraph_noField_symmetric(fei::Graph* graph,
00644                                          fei::ConnectivityBlock* cblock);
00645    int addBlockToGraph_sparse(fei::Graph* graph,
00646                               fei::ConnectivityBlock* cblock);
00647 
00648    int addPattern(fei::Pattern* pattern);
00649 
00650    int getConnectivityIndices_multiField(const snl_fei::RecordCollection*const* recordCollections,
00651                                          int* records, int numRecords,
00652                                          const int* numFieldsPerID,
00653                                          const int* fieldIDs,
00654                                          const int* fieldSizes,
00655                                          int indicesAllocLen,
00656                                          int* indices,
00657                                          int& numIndices);
00658 
00659    int getConnectivityIndices_singleField(const snl_fei::RecordCollection*const* recordCollections,
00660                                           int* records, int numRecords,
00661                                           int fieldID, int fieldSize,
00662                                           int indicesAllocLen,
00663                                           int* indices,
00664                                           int& numIndices);
00665 
00666    int getConnectivityIndices_noField(const snl_fei::RecordCollection*const* recordCollections,
00667                                       int* records,
00668                                       int numRecords,
00669                                       int indicesAllocLen,
00670                                       int* indices,
00671                                       int& numIndices);
00672 
00673    int getConnectivityRecords(fei::VectorSpace* vecSpace,
00674                               int idType,
00675                               int numIDs,
00676                               const int* IDs,
00677                               int* records);
00678 
00679    int getConnectivityRecords(fei::VectorSpace* vecSpace,
00680                               int idType,
00681                               int fieldID,
00682                               int numIDs,
00683                               const int* IDs,
00684                               int* records);
00685 
00686    int getConnectivityRecords(fei::Pattern* pattern,
00687                               fei::VectorSpace* solnSpace,
00688                               const int* connectedIdentifiers,
00689                               int* recordList);
00690 
00691    int exchangeBlkEqnSizes(fei::Graph* graph);
00692 
00693    int addLagrangeConstraintsToGraph(fei::Graph* graph);
00694 
00695    int addPenaltyConstraintsToGraph(fei::Graph* graph);
00696 
00697    void setName(const char* name);
00698 
00699  private:
00700    int localProc_, numProcs_;
00701 
00702    MPI_Comm comm_;
00703 
00704    fei::SharedPtr<fei::VectorSpace> rowSpace_;
00705    fei::SharedPtr<fei::VectorSpace> colSpace_;
00706    bool haveRowSpace_;
00707    bool haveColSpace_;
00708    bool symmetric_;
00709 
00710    fei::SharedPtr<fei::SparseRowGraph> remotelyOwnedGraphRows_;
00711 
00712    bool simpleProblem_;
00713    bool blockEntryGraph_;
00714 
00715    std::map<int,fei::Pattern*> patterns_;
00716 
00717    std::map<int,fei::ConnectivityBlock*> connectivityBlocks_;
00718    int arbitraryBlockCounter_;
00719 
00720    std::vector<fei::ConnectivityBlock*> sparseBlocks_;
00721 
00722    std::map<int, ConstraintType* >
00723      lagrangeConstraints_, penaltyConstraints_, slaveConstraints_;
00724 
00725    bool ptEqualBlk_;
00726 
00727    bool newSlaveData_;
00728 
00729    int localNumSlaves_;
00730    int globalNumSlaves_;
00731 
00732    fei::SharedPtr<FillableMat> D_;
00733    fei::SharedPtr<CSVec> g_;
00734    bool g_nonzero_;
00735 
00736    fei::SharedPtr<fei::Reducer> reducer_;
00737 
00738    std::string name_;
00739    std::string dbgprefix_;
00740 
00741    std::vector<int> tmpIntArray1_, tmpIntArray2_;
00742 
00743    int* vspcEqnPtr_;
00744 
00745    std::set<int> constrained_indices_;
00746 };//class MatrixGraph_Impl2
00747 
00748  inline fei::SharedPtr<fei::VectorSpace> MatrixGraph_Impl2::getRowSpace()
00749    {
00750      return(rowSpace_);
00751    }
00752 
00753  inline fei::SharedPtr<fei::VectorSpace> MatrixGraph_Impl2::getColSpace()
00754    {
00755      return(colSpace_);
00756    }
00757 
00758  inline std::map<int,fei::ConnectivityBlock*>& MatrixGraph_Impl2::getConnectivityBlocks()
00759    {
00760      return(connectivityBlocks_);
00761    }
00762 
00763  inline int MatrixGraph_Impl2::getGlobalNumSlaveConstraints() const
00764    {
00765      return( globalNumSlaves_ );
00766    }
00767 
00768  inline std::map<int, ConstraintType* >& MatrixGraph_Impl2::getLagrangeConstraints()
00769    {
00770      return( lagrangeConstraints_ );
00771    }
00772 }//namespace fei
00773 
00774 #endif
00775 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends