FEI Version of the Day
fei_VectorSpace.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_VectorSpace_hpp_
00045 #define _fei_VectorSpace_hpp_
00046 
00047 #include <fei_macros.hpp>
00048 #include <fei_constants.hpp>
00049 #include <fei_fwd.hpp>
00050 #include <fei_SharedPtr.hpp>
00051 #include <fei_Logger.hpp>
00052 #include <fei_utils.hpp>
00053 #include <fei_CommUtils.hpp>
00054 #include <fei_FieldDofMap.hpp>
00055 #include <fei_ctg_set.hpp>
00056 #include <snl_fei_RaggedTable.hpp>
00057 
00058 namespace fei {
00059   class FieldMask;
00060   class Lookup_Impl;
00061   class Pattern;
00062   template<typename GlobalIDType> class Record;
00063   template<typename GlobalIDType> class Record_Operator;
00064   template<typename GlobalIDType> class SharedIDs;
00065 
00097   class VectorSpace : private fei::Logger {
00098   public:
00100     class Factory {
00101     public:
00103       virtual ~Factory(){}
00104 
00106      virtual fei::SharedPtr<VectorSpace> createVectorSpace(MPI_Comm,
00107                                                            const char* name);
00108     };
00109 
00115     VectorSpace(MPI_Comm comm, const char* name = NULL);
00116 
00118     virtual ~VectorSpace();
00119 
00121 
00126     void setParameters(const fei::ParameterSet& paramset);
00127 
00140     void defineFields(int numFields,
00141                       const int* fieldIDs,
00142                       const int* fieldSizes,
00143                       const int* fieldTypes = NULL);
00144 
00154     void defineIDTypes(int numIDTypes,
00155                        const int* idTypes);
00156 
00170     int addDOFs(int fieldID,
00171                 int idType,
00172                 int numIDs,
00173                 const int* IDs);
00174 
00194     int addDOFs(int idType,
00195                 int numIDs,
00196                 const int* IDs);
00197 
00217     int initSharedIDs(int numShared,
00218                       int idType,
00219                       const int* sharedIDs,
00220                       const int* numSharingProcsPerID,
00221                       const int* sharingProcs);
00222 
00242     int initSharedIDs(int numShared,
00243                       int idType,
00244                       const int* sharedIDs,
00245                       const int* numSharingProcsPerID,
00246                       const int* const* sharingProcs);
00247 
00250     int addVectorSpace(fei::VectorSpace* inputSpace);
00251 
00258     int initComplete();
00259 
00262     bool initCompleteAlreadyCalled() const { return initCompleteAlreadyCalled_; }
00263 
00265 
00267 
00271     MPI_Comm getCommunicator() const;
00272 
00302     int getGlobalIndex(int idType,
00303                        int ID,
00304                        int fieldID,
00305                        int fieldOffset,
00306                        int whichComponentOfField,
00307                        int& globalIndex);
00308 
00329     int getGlobalIndex(int idType,
00330                        int ID,
00331                        int fieldID,
00332                        int& globalIndex);
00333 
00347     int getGlobalBlkIndex(int idType,
00348                           int ID,
00349                           int& globalBlkIndex);
00350 
00367     int getGlobalIndices(int numIDs,
00368                          const int* IDs,
00369                          int idType,
00370                          int fieldID,
00371                          int* globalIndices);
00372 
00388     int getGlobalBlkIndices(int numIDs,
00389                          const int* IDs,
00390                          int idType,
00391                          int* globalBlkIndices);
00392 
00411     int getGlobalIndices(int numIDs,
00412                          const int* IDs,
00413                          const int* idTypes,
00414                          const int* fieldIDs,                         
00415                          int* globalIndices);
00416 
00440     int getGlobalIndex(int idType,
00441                        int ID,
00442                        int& globalIndex);
00443 
00447     int getNumDegreesOfFreedom(int idType,
00448                                int ID);
00449 
00452     int getNumFields();
00453 
00458     void getFields(std::vector<int>& fieldIDs);
00459 
00463     int getNumFields(int idType, int ID);
00464 
00476     void getFields(int idType, int ID, std::vector<int>& fieldIDs);
00477 
00480     size_t getNumIDTypes();
00481 
00487     void getIDTypes(std::vector<int>& idTypes) const;
00488 
00497     void getGlobalIndexOffsets(std::vector<int>& globalOffsets) const;
00498 
00507     void getGlobalBlkIndexOffsets(std::vector<int>& globalBlkOffsets) const;
00508 
00513     int getOwnerProcPtIndex(int globalIndex);
00514 
00519     int getOwnerProcBlkIndex(int globalIndex);
00520 
00525     bool isLocal(int idType, int ID);
00526 
00530     bool isLocallyOwned(int idType, int ID);
00531 
00536     unsigned getFieldSize(int fieldID);
00537 
00539     int getNumOwnedAndSharedIDs(int idType);
00540 
00542     int getNumOwnedIDs(int idType);
00543 
00546     int getOwnedAndSharedIDs(int idtype,
00547                     int lenList,
00548                     int* IDs,
00549                     int& numLocalIDs);
00550 
00553     int getOwnedIDs(int idtype,
00554                            int lenList,
00555                            int* IDs,
00556                            int& numLocalIDs);
00557 
00562     int getNumIndices_SharedAndOwned() const;
00563 
00571     int getIndices_SharedAndOwned(std::vector<int>& globalIndices) const;
00572 
00577     int getNumBlkIndices_SharedAndOwned(int& numBlkIndices) const;
00578 
00594     int getBlkIndices_SharedAndOwned(int lenBlkIndices,
00595                                      int* globalBlkIndices,
00596                                      int* blkSizes,
00597                                      int& numBlkIndices);
00598 
00601     int getNumIndices_Owned() const;
00602 
00613     int getIndices_Owned(std::vector<int>& globalIndices) const;
00614     int getIndices_Owned(int lenIndices, int* globalIndices, int& numIndices) const;
00615 
00618     int getNumBlkIndices_Owned() const;
00619 
00633     int getBlkIndices_Owned(int lenBlkIndices,
00634                             int* globalBlkIndices,
00635                             int* blkSizes,
00636                             int& numBlkIndices);
00637 
00639     int getNumSharedIDs(int idType, int& numShared);
00640 
00643     int getGlobalNumIndices() const;
00644 
00647     int getGlobalNumBlkIndices() const;
00648 
00651     int getRecordCollection(int idType, snl_fei::RecordCollection*& records);
00652 
00655     int getRecordCollection(int idType, const snl_fei::RecordCollection*& records) const;
00656 
00659     std::vector<int>& getEqnNumbers();
00660 
00663     const std::vector<int>& getEqnNumbers() const;
00664 
00667     snl_fei::PointBlockMap* getPointBlockMap();
00668     const snl_fei::PointBlockMap* getPointBlockMap() const;
00669 
00670     fei::FieldDofMap<int>& getFieldDofMap();
00671 
00672     void getGlobalIndices(const fei::Pattern* pattern,
00673                           const fei::Record<int>*const* records,
00674                           std::vector<int>& indices);
00675 
00676     void getGlobalIndicesL(const fei::Pattern* pattern,
00677                           const int* records,
00678                           std::vector<int>& indices);
00679 
00680     void getGlobalBlkIndices(const fei::Pattern* pattern,
00681                              const fei::Record<int>*const* records,
00682                              std::vector<int>& indices);
00683 
00684     void getGlobalIndices(int numRecords,
00685                           const fei::Record<int>*const* records,
00686                           int fieldID,
00687                           int fieldSize,
00688                           int indicesAllocLen,
00689                           int* indices,
00690                           int& numIndices);
00691 
00692     void getGlobalIndicesL(int numRecords,
00693                           const snl_fei::RecordCollection*const* recordCollections,
00694                           const int* records,
00695                           int fieldID,
00696                           int fieldSize,
00697                           int indicesAllocLen,
00698                           int* indices,
00699                           int& numIndices);
00700 
00701     void getGlobalIndices(int numRecords,
00702                           const fei::Record<int>*const* records,
00703                           const int* numFieldsPerID,
00704                           const int* fieldIDs,
00705                           const int* fieldSizes,
00706                           int indicesAllocLen,
00707                           int* indices,
00708                           int& numIndices);
00709 
00710     void getGlobalIndicesL(int numRecords,
00711                           const snl_fei::RecordCollection*const* recordCollections,
00712                           const int* records,
00713                           const int* numFieldsPerID,
00714                           const int* fieldIDs,
00715                           const int* fieldSizes,
00716                           int indicesAllocLen,
00717                           int* indices,
00718                           int& numIndices);
00719 
00720     void getGlobalBlkIndices(int numRecords,
00721                              const fei::Record<int>*const* records,
00722                              int indicesAllocLen,
00723                              int* indices,
00724                              int& numIndices);
00725 
00726     void getGlobalBlkIndicesL(int numRecords,
00727                              const snl_fei::RecordCollection*const* recordCollections,
00728                              const int* records,
00729                              int indicesAllocLen,
00730                              int* indices,
00731                              int& numIndices);
00732 
00733     int addDOFs(int fieldID,
00734                             int idType,
00735                             int numIDs,
00736                             const int* IDs,
00737                             int* records);
00738 
00739     int addDOFs(int idType,
00740                             int numIDs,
00741                             const int* IDs,
00742                             int* records);
00743 
00744     std::vector<fei::FieldMask*> fieldMasks_;
00745 
00746     void getSendProcs(std::vector<int>& sendProcs) const;
00747 
00748   private:
00749     friend class fei::Lookup_Impl;
00750 
00751   private:
00752     VectorSpace(const VectorSpace& src);
00753     VectorSpace& operator=(const VectorSpace& src);
00754 
00755     void compute_shared_ids();
00756 
00757     inline void check_version() { fei::utils::version(); }
00758 
00759     void setOwners_lowestSharing();
00760 
00761     int calculateGlobalIndices();
00762 
00763     void runRecords(fei::Record_Operator<int>& record_op);
00764 
00765     int synchronizeSharedRecords();
00766 
00767     int setLocalEqnNumbers();
00768 
00769     int exchangeGlobalIndices();
00770 
00771     int exchangeFieldInfo(fei::comm_map* ownerPattern,
00772                           fei::comm_map* sharerPattern,
00773                           snl_fei::RecordCollection* recordCollection,
00774                           std::vector<fei::FieldMask*>& fieldMasks);
00775 
00776     fei::SharedIDs<int>& getSharedIDs_private(int idType);
00777 
00778     void setName(const char* name);
00779 
00780   private:
00781     MPI_Comm comm_;
00782 
00783     std::vector<int> idTypes_;
00784     std::map<int,unsigned> fieldDatabase_;
00785     fei::FieldDofMap<int> fieldDofMap_;
00786     int maxFieldSize_;
00787     std::vector<snl_fei::RecordCollection*> recordCollections_;
00788 
00789     std::map<int, fei::SharedIDs<int> > sharedIDTables_;
00790     std::map<int, fei::comm_map*> ownerPatterns_;
00791     std::map<int, fei::comm_map*> sharerPatterns_;
00792 
00793     bool sharedRecordsSynchronized_;
00794 
00795     snl_fei::PointBlockMap* ptBlkMap_;
00796 
00797     std::vector<int> globalOffsets_;
00798     std::vector<int> globalIDOffsets_;
00799 
00800     bool simpleProblem_;
00801 
00802     int firstLocalOffset_, lastLocalOffset_;
00803 
00804     std::vector<int> eqnNumbers_;
00805 
00806     bool newInitData_;
00807     bool initCompleteAlreadyCalled_;
00808 
00809     std::string name_;
00810     std::string dbgprefix_;
00811     bool checkSharedIDs_;
00812   }; // class fei::VectorSpace
00813 
00814   inline std::vector<int>& VectorSpace::getEqnNumbers()
00815     {
00816       return( eqnNumbers_ );
00817     }
00818 
00819   inline const std::vector<int>& VectorSpace::getEqnNumbers() const
00820     {
00821       return( eqnNumbers_ );
00822     }
00823 
00824   inline snl_fei::PointBlockMap* VectorSpace::getPointBlockMap()
00825     {
00826       return( ptBlkMap_ );
00827     }
00828 
00829   inline const snl_fei::PointBlockMap* VectorSpace::getPointBlockMap() const
00830     {
00831       return( ptBlkMap_ );
00832     }
00833 
00834 } // namespace fei
00835 
00836 #endif // _fei_VectorSpace_hpp_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends