FEI Version of the Day
fei_VectorSpace.hpp
00001 /*--------------------------------------------------------------------*/
00002 /*    Copyright 2005 Sandia Corporation.                              */
00003 /*    Under the terms of Contract DE-AC04-94AL85000, there is a       */
00004 /*    non-exclusive license for use of this work by or on behalf      */
00005 /*    of the U.S. Government.  Export of this program may require     */
00006 /*    a license from the United States Government.                    */
00007 /*--------------------------------------------------------------------*/
00008 
00009 #ifndef _fei_VectorSpace_hpp_
00010 #define _fei_VectorSpace_hpp_
00011 
00012 #include <fei_macros.hpp>
00013 #include <fei_constants.hpp>
00014 #include <fei_fwd.hpp>
00015 #include <fei_SharedPtr.hpp>
00016 #include <fei_Logger.hpp>
00017 #include <fei_utils.hpp>
00018 #include <fei_CommUtils.hpp>
00019 #include <fei_FieldDofMap.hpp>
00020 #include <fei_ctg_set.hpp>
00021 #include <snl_fei_RaggedTable.hpp>
00022 
00023 namespace fei {
00024   class FieldMask;
00025   class Lookup_Impl;
00026   class Pattern;
00027   template<typename GlobalIDType> class Record;
00028   template<typename GlobalIDType> class Record_Operator;
00029   template<typename GlobalIDType> class SharedIDs;
00030 
00062   class VectorSpace : private fei::Logger {
00063   public:
00065     class Factory {
00066     public:
00068       virtual ~Factory(){}
00069 
00071      virtual fei::SharedPtr<VectorSpace> createVectorSpace(MPI_Comm,
00072                                                            const char* name);
00073     };
00074 
00080     VectorSpace(MPI_Comm comm, const char* name = NULL);
00081 
00083     virtual ~VectorSpace();
00084 
00086 
00091     void setParameters(const fei::ParameterSet& paramset);
00092 
00105     void defineFields(int numFields,
00106                       const int* fieldIDs,
00107                       const int* fieldSizes,
00108                       const int* fieldTypes = NULL);
00109 
00119     void defineIDTypes(int numIDTypes,
00120                        const int* idTypes);
00121 
00122     void setIDMap(int idType,
00123                   const int* localIDs_begin, const int* localIDs_end,
00124                   const int* globalIDs_begin, const int* globalIDs_end);
00125 
00139     int addDOFs(int fieldID,
00140                 int idType,
00141                 int numIDs,
00142                 const int* IDs);
00143 
00163     int addDOFs(int idType,
00164                 int numIDs,
00165                 const int* IDs);
00166 
00186     int initSharedIDs(int numShared,
00187                       int idType,
00188                       const int* sharedIDs,
00189                       const int* numSharingProcsPerID,
00190                       const int* sharingProcs);
00191 
00211     int initSharedIDs(int numShared,
00212                       int idType,
00213                       const int* sharedIDs,
00214                       const int* numSharingProcsPerID,
00215                       const int* const* sharingProcs);
00216 
00217     int setOwners(int numShared, int idType, const int* sharedIDs, const int* owners);
00218 
00221     int addVectorSpace(fei::VectorSpace* inputSpace);
00222 
00229     int initComplete();
00230 
00233     bool initCompleteAlreadyCalled() const { return initCompleteAlreadyCalled_; }
00234 
00236 
00238 
00242     MPI_Comm getCommunicator() const;
00243 
00273     int getGlobalIndex(int idType,
00274                        int ID,
00275                        int fieldID,
00276                        int fieldOffset,
00277                        int whichComponentOfField,
00278                        int& globalIndex);
00279 
00300     int getGlobalIndex(int idType,
00301                        int ID,
00302                        int fieldID,
00303                        int& globalIndex);
00304 
00318     int getGlobalBlkIndex(int idType,
00319                           int ID,
00320                           int& globalBlkIndex);
00321 
00338     int getGlobalIndices(int numIDs,
00339                          const int* IDs,
00340                          int idType,
00341                          int fieldID,
00342                          int* globalIndices);
00343 
00360     int getGlobalIndicesLocalIDs(int numIDs,
00361                          const int* localIDs,
00362                          int idType,
00363                          int fieldID,
00364                          int* globalIndices);
00365 
00381     int getGlobalBlkIndices(int numIDs,
00382                          const int* IDs,
00383                          int idType,
00384                          int* globalBlkIndices);
00385 
00404     int getGlobalIndices(int numIDs,
00405                          const int* IDs,
00406                          const int* idTypes,
00407                          const int* fieldIDs,                         
00408                          int* globalIndices);
00409 
00433     int getGlobalIndex(int idType,
00434                        int ID,
00435                        int& globalIndex);
00436 
00440     int getNumDegreesOfFreedom(int idType,
00441                                int ID);
00442 
00445     int getNumFields();
00446 
00451     void getFields(std::vector<int>& fieldIDs);
00452 
00456     int getNumFields(int idType, int ID);
00457 
00469     void getFields(int idType, int ID, std::vector<int>& fieldIDs);
00470 
00473     size_t getNumIDTypes();
00474 
00480     void getIDTypes(std::vector<int>& idTypes) const;
00481 
00490     void getGlobalIndexOffsets(std::vector<int>& globalOffsets) const;
00491 
00500     void getGlobalBlkIndexOffsets(std::vector<int>& globalBlkOffsets) const;
00501 
00506     int getOwnerProcPtIndex(int globalIndex);
00507 
00512     int getOwnerProcBlkIndex(int globalIndex);
00513 
00518     bool isLocal(int idType, int ID);
00519 
00523     bool isLocallyOwned(int idType, int ID);
00524 
00529     unsigned getFieldSize(int fieldID);
00530 
00532     int getNumOwnedAndSharedIDs(int idType);
00533 
00535     int getNumOwnedIDs(int idType);
00536 
00539     int getOwnedAndSharedIDs(int idtype,
00540                     int lenList,
00541                     int* IDs,
00542                     int& numOwnedAndSharedIDs);
00543 
00546     int getOwnedIDs(int idtype,
00547                            int lenList,
00548                            int* IDs,
00549                            int& numLocalIDs);
00550 
00555     int getNumIndices_SharedAndOwned() const;
00556 
00564     int getIndices_SharedAndOwned(std::vector<int>& globalIndices) const;
00565 
00570     int getNumBlkIndices_SharedAndOwned(int& numBlkIndices) const;
00571 
00587     int getBlkIndices_SharedAndOwned(int lenBlkIndices,
00588                                      int* globalBlkIndices,
00589                                      int* blkSizes,
00590                                      int& numBlkIndices);
00591 
00594     int getNumIndices_Owned() const;
00595 
00606     int getIndices_Owned(std::vector<int>& globalIndices) const;
00607     int getIndices_Owned(int lenIndices, int* globalIndices, int& numIndices) const;
00608 
00611     int getNumBlkIndices_Owned() const;
00612 
00626     int getBlkIndices_Owned(int lenBlkIndices,
00627                             int* globalBlkIndices,
00628                             int* blkSizes,
00629                             int& numBlkIndices);
00630 
00632     int getNumSharedIDs(int idType, int& numShared);
00633 
00636     int getGlobalNumIndices() const;
00637 
00640     int getGlobalNumBlkIndices() const;
00641 
00644     int getRecordCollection(int idType, snl_fei::RecordCollection*& records);
00645 
00648     int getRecordCollection(int idType, const snl_fei::RecordCollection*& records) const;
00649 
00652     std::vector<int>& getEqnNumbers();
00653 
00656     const std::vector<int>& getEqnNumbers() const;
00657 
00660     snl_fei::PointBlockMap* getPointBlockMap();
00661     const snl_fei::PointBlockMap* getPointBlockMap() const;
00662 
00663     fei::FieldDofMap<int>& getFieldDofMap();
00664 
00665     void getGlobalIndices(const fei::Pattern* pattern,
00666                           const fei::Record<int>*const* records,
00667                           std::vector<int>& indices);
00668 
00669     void getGlobalIndicesL(const fei::Pattern* pattern,
00670                           const int* records,
00671                           std::vector<int>& indices);
00672 
00673     void getGlobalBlkIndices(const fei::Pattern* pattern,
00674                              const fei::Record<int>*const* records,
00675                              std::vector<int>& indices);
00676 
00677     void getGlobalIndices(int numRecords,
00678                           const fei::Record<int>*const* records,
00679                           int fieldID,
00680                           int fieldSize,
00681                           int indicesAllocLen,
00682                           int* indices,
00683                           int& numIndices);
00684 
00685     void getGlobalIndicesL(int numRecords,
00686                           const snl_fei::RecordCollection*const* recordCollections,
00687                           const int* records,
00688                           int fieldID,
00689                           int fieldSize,
00690                           int indicesAllocLen,
00691                           int* indices,
00692                           int& numIndices);
00693 
00694     void getGlobalIndices(int numRecords,
00695                           const fei::Record<int>*const* records,
00696                           const int* numFieldsPerID,
00697                           const int* fieldIDs,
00698                           const int* fieldSizes,
00699                           int indicesAllocLen,
00700                           int* indices,
00701                           int& numIndices);
00702 
00703     void getGlobalIndicesL(int numRecords,
00704                           const snl_fei::RecordCollection*const* recordCollections,
00705                           const int* records,
00706                           const int* numFieldsPerID,
00707                           const int* fieldIDs,
00708                           const int* fieldSizes,
00709                           int indicesAllocLen,
00710                           int* indices,
00711                           int& numIndices);
00712 
00713     void getGlobalBlkIndices(int numRecords,
00714                              const fei::Record<int>*const* records,
00715                              int indicesAllocLen,
00716                              int* indices,
00717                              int& numIndices);
00718 
00719     void getGlobalBlkIndicesL(int numRecords,
00720                              const snl_fei::RecordCollection*const* recordCollections,
00721                              const int* records,
00722                              int indicesAllocLen,
00723                              int* indices,
00724                              int& numIndices);
00725 
00726     int addDOFs(int fieldID,
00727                             int idType,
00728                             int numIDs,
00729                             const int* IDs,
00730                             int* records);
00731 
00732     int addDOFs(int idType,
00733                             int numIDs,
00734                             const int* IDs,
00735                             int* records);
00736 
00737     std::vector<fei::FieldMask*> fieldMasks_;
00738 
00739     void getSendProcs(std::vector<int>& sendProcs) const;
00740 
00741     fei::SharedIDs<int>& getSharedIDs(int idType);
00742 
00743   private:
00744     friend class fei::Lookup_Impl;
00745 
00746   private:
00747     VectorSpace(const VectorSpace& src);
00748     VectorSpace& operator=(const VectorSpace& src);
00749 
00750     void compute_shared_ids(const std::vector<int>& global_min, const std::vector<int>& global_max);
00751 
00752     inline void check_version() { fei::utils::version(); }
00753 
00754     void setOwners_shared();
00755 
00756     int calculateGlobalIndices();
00757 
00758     void runRecords(fei::Record_Operator<int>& record_op);
00759 
00760     int synchronizeSharedRecords();
00761 
00762     int setLocalEqnNumbers();
00763 
00764     int exchangeGlobalIndices();
00765 
00766     int exchangeFieldInfo(fei::comm_map* ownerPattern,
00767                           fei::comm_map* sharerPattern,
00768                           snl_fei::RecordCollection* recordCollection,
00769                           std::vector<fei::FieldMask*>& fieldMasks);
00770 
00771     void setName(const char* name);
00772 
00773   private:
00774     MPI_Comm comm_;
00775 
00776     std::vector<int> idTypes_;
00777     std::map<int,unsigned> fieldDatabase_;
00778     fei::FieldDofMap<int> fieldDofMap_;
00779     int maxFieldSize_;
00780     std::vector<snl_fei::RecordCollection*> recordCollections_;
00781 
00782     std::map<int, fei::SharedIDs<int> > sharedIDTables_;
00783     std::map<int, fei::comm_map*> ownerPatterns_;
00784     std::map<int, fei::comm_map*> sharerPatterns_;
00785 
00786     bool sharedRecordsSynchronized_;
00787 
00788     snl_fei::PointBlockMap* ptBlkMap_;
00789 
00790     std::vector<int> globalOffsets_;
00791     std::vector<int> globalIDOffsets_;
00792 
00793     bool simpleProblem_;
00794 
00795     int firstLocalOffset_, lastLocalOffset_;
00796 
00797     std::vector<int> eqnNumbers_;
00798 
00799     bool newInitData_;
00800     bool initCompleteAlreadyCalled_;
00801 
00802     std::string name_;
00803     std::string dbgprefix_;
00804     bool checkSharedIDs_;
00805   }; // class fei::VectorSpace
00806 
00807   inline std::vector<int>& VectorSpace::getEqnNumbers()
00808     {
00809       return( eqnNumbers_ );
00810     }
00811 
00812   inline const std::vector<int>& VectorSpace::getEqnNumbers() const
00813     {
00814       return( eqnNumbers_ );
00815     }
00816 
00817   inline snl_fei::PointBlockMap* VectorSpace::getPointBlockMap()
00818     {
00819       return( ptBlkMap_ );
00820     }
00821 
00822   inline const snl_fei::PointBlockMap* VectorSpace::getPointBlockMap() const
00823     {
00824       return( ptBlkMap_ );
00825     }
00826 
00827 } // namespace fei
00828 
00829 #endif // _fei_VectorSpace_hpp_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends