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 
00157     void setIDMap(int idType,
00158                   const int* localIDs_begin, const int* localIDs_end,
00159                   const int* globalIDs_begin, const int* globalIDs_end);
00160 
00174     int addDOFs(int fieldID,
00175                 int idType,
00176                 int numIDs,
00177                 const int* IDs);
00178 
00198     int addDOFs(int idType,
00199                 int numIDs,
00200                 const int* IDs);
00201 
00221     int initSharedIDs(int numShared,
00222                       int idType,
00223                       const int* sharedIDs,
00224                       const int* numSharingProcsPerID,
00225                       const int* sharingProcs);
00226 
00246     int initSharedIDs(int numShared,
00247                       int idType,
00248                       const int* sharedIDs,
00249                       const int* numSharingProcsPerID,
00250                       const int* const* sharingProcs);
00251 
00254     int addVectorSpace(fei::VectorSpace* inputSpace);
00255 
00262     int initComplete();
00263 
00266     bool initCompleteAlreadyCalled() const { return initCompleteAlreadyCalled_; }
00267 
00269 
00271 
00275     MPI_Comm getCommunicator() const;
00276 
00306     int getGlobalIndex(int idType,
00307                        int ID,
00308                        int fieldID,
00309                        int fieldOffset,
00310                        int whichComponentOfField,
00311                        int& globalIndex);
00312 
00333     int getGlobalIndex(int idType,
00334                        int ID,
00335                        int fieldID,
00336                        int& globalIndex);
00337 
00351     int getGlobalBlkIndex(int idType,
00352                           int ID,
00353                           int& globalBlkIndex);
00354 
00371     int getGlobalIndices(int numIDs,
00372                          const int* IDs,
00373                          int idType,
00374                          int fieldID,
00375                          int* globalIndices);
00376 
00393     int getGlobalIndicesLocalIDs(int numIDs,
00394                          const int* localIDs,
00395                          int idType,
00396                          int fieldID,
00397                          int* globalIndices);
00398 
00414     int getGlobalBlkIndices(int numIDs,
00415                          const int* IDs,
00416                          int idType,
00417                          int* globalBlkIndices);
00418 
00437     int getGlobalIndices(int numIDs,
00438                          const int* IDs,
00439                          const int* idTypes,
00440                          const int* fieldIDs,                         
00441                          int* globalIndices);
00442 
00466     int getGlobalIndex(int idType,
00467                        int ID,
00468                        int& globalIndex);
00469 
00473     int getNumDegreesOfFreedom(int idType,
00474                                int ID);
00475 
00478     int getNumFields();
00479 
00484     void getFields(std::vector<int>& fieldIDs);
00485 
00489     int getNumFields(int idType, int ID);
00490 
00502     void getFields(int idType, int ID, std::vector<int>& fieldIDs);
00503 
00506     size_t getNumIDTypes();
00507 
00513     void getIDTypes(std::vector<int>& idTypes) const;
00514 
00523     void getGlobalIndexOffsets(std::vector<int>& globalOffsets) const;
00524 
00533     void getGlobalBlkIndexOffsets(std::vector<int>& globalBlkOffsets) const;
00534 
00539     int getOwnerProcPtIndex(int globalIndex);
00540 
00545     int getOwnerProcBlkIndex(int globalIndex);
00546 
00551     bool isLocal(int idType, int ID);
00552 
00556     bool isLocallyOwned(int idType, int ID);
00557 
00562     unsigned getFieldSize(int fieldID);
00563 
00565     int getNumOwnedAndSharedIDs(int idType);
00566 
00568     int getNumOwnedIDs(int idType);
00569 
00572     int getOwnedAndSharedIDs(int idtype,
00573                     int lenList,
00574                     int* IDs,
00575                     int& numOwnedAndSharedIDs);
00576 
00579     int getOwnedIDs(int idtype,
00580                            int lenList,
00581                            int* IDs,
00582                            int& numLocalIDs);
00583 
00588     int getNumIndices_SharedAndOwned() const;
00589 
00597     int getIndices_SharedAndOwned(std::vector<int>& globalIndices) const;
00598 
00603     int getNumBlkIndices_SharedAndOwned(int& numBlkIndices) const;
00604 
00620     int getBlkIndices_SharedAndOwned(int lenBlkIndices,
00621                                      int* globalBlkIndices,
00622                                      int* blkSizes,
00623                                      int& numBlkIndices);
00624 
00627     int getNumIndices_Owned() const;
00628 
00639     int getIndices_Owned(std::vector<int>& globalIndices) const;
00640     int getIndices_Owned(int lenIndices, int* globalIndices, int& numIndices) const;
00641 
00644     int getNumBlkIndices_Owned() const;
00645 
00659     int getBlkIndices_Owned(int lenBlkIndices,
00660                             int* globalBlkIndices,
00661                             int* blkSizes,
00662                             int& numBlkIndices);
00663 
00665     int getNumSharedIDs(int idType, int& numShared);
00666 
00669     int getGlobalNumIndices() const;
00670 
00673     int getGlobalNumBlkIndices() const;
00674 
00677     int getRecordCollection(int idType, snl_fei::RecordCollection*& records);
00678 
00681     int getRecordCollection(int idType, const snl_fei::RecordCollection*& records) const;
00682 
00685     std::vector<int>& getEqnNumbers();
00686 
00689     const std::vector<int>& getEqnNumbers() const;
00690 
00693     snl_fei::PointBlockMap* getPointBlockMap();
00694     const snl_fei::PointBlockMap* getPointBlockMap() const;
00695 
00696     fei::FieldDofMap<int>& getFieldDofMap();
00697 
00698     void getGlobalIndices(const fei::Pattern* pattern,
00699                           const fei::Record<int>*const* records,
00700                           std::vector<int>& indices);
00701 
00702     void getGlobalIndicesL(const fei::Pattern* pattern,
00703                           const int* records,
00704                           std::vector<int>& indices);
00705 
00706     void getGlobalBlkIndices(const fei::Pattern* pattern,
00707                              const fei::Record<int>*const* records,
00708                              std::vector<int>& indices);
00709 
00710     void getGlobalIndices(int numRecords,
00711                           const fei::Record<int>*const* records,
00712                           int fieldID,
00713                           int fieldSize,
00714                           int indicesAllocLen,
00715                           int* indices,
00716                           int& numIndices);
00717 
00718     void getGlobalIndicesL(int numRecords,
00719                           const snl_fei::RecordCollection*const* recordCollections,
00720                           const int* records,
00721                           int fieldID,
00722                           int fieldSize,
00723                           int indicesAllocLen,
00724                           int* indices,
00725                           int& numIndices);
00726 
00727     void getGlobalIndices(int numRecords,
00728                           const fei::Record<int>*const* records,
00729                           const int* numFieldsPerID,
00730                           const int* fieldIDs,
00731                           const int* fieldSizes,
00732                           int indicesAllocLen,
00733                           int* indices,
00734                           int& numIndices);
00735 
00736     void getGlobalIndicesL(int numRecords,
00737                           const snl_fei::RecordCollection*const* recordCollections,
00738                           const int* records,
00739                           const int* numFieldsPerID,
00740                           const int* fieldIDs,
00741                           const int* fieldSizes,
00742                           int indicesAllocLen,
00743                           int* indices,
00744                           int& numIndices);
00745 
00746     void getGlobalBlkIndices(int numRecords,
00747                              const fei::Record<int>*const* records,
00748                              int indicesAllocLen,
00749                              int* indices,
00750                              int& numIndices);
00751 
00752     void getGlobalBlkIndicesL(int numRecords,
00753                              const snl_fei::RecordCollection*const* recordCollections,
00754                              const int* records,
00755                              int indicesAllocLen,
00756                              int* indices,
00757                              int& numIndices);
00758 
00759     int addDOFs(int fieldID,
00760                             int idType,
00761                             int numIDs,
00762                             const int* IDs,
00763                             int* records);
00764 
00765     int addDOFs(int idType,
00766                             int numIDs,
00767                             const int* IDs,
00768                             int* records);
00769 
00770     std::vector<fei::FieldMask*> fieldMasks_;
00771 
00772     void getSendProcs(std::vector<int>& sendProcs) const;
00773 
00774     fei::SharedIDs<int>& getSharedIDs(int idType);
00775 
00776   private:
00777     friend class fei::Lookup_Impl;
00778 
00779   private:
00780     VectorSpace(const VectorSpace& src);
00781     VectorSpace& operator=(const VectorSpace& src);
00782 
00783     void compute_shared_ids();
00784 
00785     inline void check_version() { fei::utils::version(); }
00786 
00787     void setOwners_lowestSharing();
00788 
00789     int calculateGlobalIndices();
00790 
00791     void runRecords(fei::Record_Operator<int>& record_op);
00792 
00793     int synchronizeSharedRecords();
00794 
00795     int setLocalEqnNumbers();
00796 
00797     int exchangeGlobalIndices();
00798 
00799     int exchangeFieldInfo(fei::comm_map* ownerPattern,
00800                           fei::comm_map* sharerPattern,
00801                           snl_fei::RecordCollection* recordCollection,
00802                           std::vector<fei::FieldMask*>& fieldMasks);
00803 
00804     void setName(const char* name);
00805 
00806   private:
00807     MPI_Comm comm_;
00808 
00809     std::vector<int> idTypes_;
00810     std::map<int,unsigned> fieldDatabase_;
00811     fei::FieldDofMap<int> fieldDofMap_;
00812     int maxFieldSize_;
00813     std::vector<snl_fei::RecordCollection*> recordCollections_;
00814 
00815     std::map<int, fei::SharedIDs<int> > sharedIDTables_;
00816     std::map<int, fei::comm_map*> ownerPatterns_;
00817     std::map<int, fei::comm_map*> sharerPatterns_;
00818 
00819     bool sharedRecordsSynchronized_;
00820 
00821     snl_fei::PointBlockMap* ptBlkMap_;
00822 
00823     std::vector<int> globalOffsets_;
00824     std::vector<int> globalIDOffsets_;
00825 
00826     bool simpleProblem_;
00827 
00828     int firstLocalOffset_, lastLocalOffset_;
00829 
00830     std::vector<int> eqnNumbers_;
00831 
00832     bool newInitData_;
00833     bool initCompleteAlreadyCalled_;
00834 
00835     std::string name_;
00836     std::string dbgprefix_;
00837     bool checkSharedIDs_;
00838   }; // class fei::VectorSpace
00839 
00840   inline std::vector<int>& VectorSpace::getEqnNumbers()
00841     {
00842       return( eqnNumbers_ );
00843     }
00844 
00845   inline const std::vector<int>& VectorSpace::getEqnNumbers() const
00846     {
00847       return( eqnNumbers_ );
00848     }
00849 
00850   inline snl_fei::PointBlockMap* VectorSpace::getPointBlockMap()
00851     {
00852       return( ptBlkMap_ );
00853     }
00854 
00855   inline const snl_fei::PointBlockMap* VectorSpace::getPointBlockMap() const
00856     {
00857       return( ptBlkMap_ );
00858     }
00859 
00860 } // namespace fei
00861 
00862 #endif // _fei_VectorSpace_hpp_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends