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();
00260 
00262 
00266     MPI_Comm getCommunicator() const;
00267 
00297     int getGlobalIndex(int idType,
00298                        int ID,
00299                        int fieldID,
00300                        int fieldOffset,
00301                        int whichComponentOfField,
00302                        int& globalIndex);
00303 
00324     int getGlobalIndex(int idType,
00325                        int ID,
00326                        int fieldID,
00327                        int& globalIndex);
00328 
00342     int getGlobalBlkIndex(int idType,
00343                           int ID,
00344                           int& globalBlkIndex);
00345 
00362     int getGlobalIndices(int numIDs,
00363                          const int* IDs,
00364                          int idType,
00365                          int fieldID,
00366                          int* globalIndices);
00367 
00383     int getGlobalBlkIndices(int numIDs,
00384                          const int* IDs,
00385                          int idType,
00386                          int* globalBlkIndices);
00387 
00406     int getGlobalIndices(int numIDs,
00407                          const int* IDs,
00408                          const int* idTypes,
00409                          const int* fieldIDs,                         
00410                          int* globalIndices);
00411 
00435     int getGlobalIndex(int idType,
00436                        int ID,
00437                        int& globalIndex);
00438 
00442     int getNumDegreesOfFreedom(int idType,
00443                                int ID);
00444 
00447     int getNumFields();
00448 
00453     void getFields(std::vector<int>& fieldIDs);
00454 
00458     int getNumFields(int idType, int ID);
00459 
00471     void getFields(int idType, int ID, std::vector<int>& fieldIDs);
00472 
00475     size_t getNumIDTypes();
00476 
00482     void getIDTypes(std::vector<int>& idTypes) const;
00483 
00492     void getGlobalIndexOffsets(std::vector<int>& globalOffsets) const;
00493 
00502     void getGlobalBlkIndexOffsets(std::vector<int>& globalBlkOffsets) const;
00503 
00508     int getOwnerProcPtIndex(int globalIndex);
00509 
00514     int getOwnerProcBlkIndex(int globalIndex);
00515 
00520     bool isLocal(int idType, int ID);
00521 
00525     bool isLocallyOwned(int idType, int ID);
00526 
00531     unsigned getFieldSize(int fieldID);
00532 
00534     int getNumOwnedAndSharedIDs(int idType);
00535 
00537     int getNumOwnedIDs(int idType);
00538 
00541     int getOwnedAndSharedIDs(int idtype,
00542                     int lenList,
00543                     int* IDs,
00544                     int& numLocalIDs);
00545 
00548     int getOwnedIDs(int idtype,
00549                            int lenList,
00550                            int* IDs,
00551                            int& numLocalIDs);
00552 
00557     int getNumIndices_SharedAndOwned() const;
00558 
00566     int getIndices_SharedAndOwned(std::vector<int>& globalIndices) const;
00567 
00572     int getNumBlkIndices_SharedAndOwned(int& numBlkIndices) const;
00573 
00589     int getBlkIndices_SharedAndOwned(int lenBlkIndices,
00590                                      int* globalBlkIndices,
00591                                      int* blkSizes,
00592                                      int& numBlkIndices);
00593 
00596     int getNumIndices_Owned() const;
00597 
00608     int getIndices_Owned(std::vector<int>& globalIndices) const;
00609     int getIndices_Owned(int lenIndices, int* globalIndices, int& numIndices) const;
00610 
00613     int getNumBlkIndices_Owned() const;
00614 
00628     int getBlkIndices_Owned(int lenBlkIndices,
00629                             int* globalBlkIndices,
00630                             int* blkSizes,
00631                             int& numBlkIndices);
00632 
00634     int getNumSharedIDs(int idType, int& numShared);
00635 
00638     int getGlobalNumIndices() const;
00639 
00642     int getGlobalNumBlkIndices() const;
00643 
00646     int getRecordCollection(int idType, snl_fei::RecordCollection*& records);
00647 
00650     int getRecordCollection(int idType, const snl_fei::RecordCollection*& records) const;
00651 
00654     std::vector<int>& getEqnNumbers();
00655 
00658     const std::vector<int>& getEqnNumbers() const;
00659 
00662     snl_fei::PointBlockMap* getPointBlockMap();
00663     const snl_fei::PointBlockMap* getPointBlockMap() const;
00664 
00665     fei::FieldDofMap<int>& getFieldDofMap();
00666 
00667     void getGlobalIndices(const fei::Pattern* pattern,
00668                           const fei::Record<int>*const* records,
00669                           std::vector<int>& indices);
00670 
00671     void getGlobalIndicesL(const fei::Pattern* pattern,
00672                           const int* records,
00673                           std::vector<int>& indices);
00674 
00675     void getGlobalBlkIndices(const fei::Pattern* pattern,
00676                              const fei::Record<int>*const* records,
00677                              std::vector<int>& indices);
00678 
00679     void getGlobalIndices(int numRecords,
00680                           const fei::Record<int>*const* records,
00681                           int fieldID,
00682                           int fieldSize,
00683                           int indicesAllocLen,
00684                           int* indices,
00685                           int& numIndices);
00686 
00687     void getGlobalIndicesL(int numRecords,
00688                           const snl_fei::RecordCollection*const* recordCollections,
00689                           const int* records,
00690                           int fieldID,
00691                           int fieldSize,
00692                           int indicesAllocLen,
00693                           int* indices,
00694                           int& numIndices);
00695 
00696     void getGlobalIndices(int numRecords,
00697                           const fei::Record<int>*const* records,
00698                           const int* numFieldsPerID,
00699                           const int* fieldIDs,
00700                           const int* fieldSizes,
00701                           int indicesAllocLen,
00702                           int* indices,
00703                           int& numIndices);
00704 
00705     void getGlobalIndicesL(int numRecords,
00706                           const snl_fei::RecordCollection*const* recordCollections,
00707                           const int* records,
00708                           const int* numFieldsPerID,
00709                           const int* fieldIDs,
00710                           const int* fieldSizes,
00711                           int indicesAllocLen,
00712                           int* indices,
00713                           int& numIndices);
00714 
00715     void getGlobalBlkIndices(int numRecords,
00716                              const fei::Record<int>*const* records,
00717                              int indicesAllocLen,
00718                              int* indices,
00719                              int& numIndices);
00720 
00721     void getGlobalBlkIndicesL(int numRecords,
00722                              const snl_fei::RecordCollection*const* recordCollections,
00723                              const int* records,
00724                              int indicesAllocLen,
00725                              int* indices,
00726                              int& numIndices);
00727 
00728     int addDOFs(int fieldID,
00729                             int idType,
00730                             int numIDs,
00731                             const int* IDs,
00732                             int* records);
00733 
00734     int addDOFs(int idType,
00735                             int numIDs,
00736                             const int* IDs,
00737                             int* records);
00738 
00739     std::vector<fei::FieldMask*> fieldMasks_;
00740 
00741     void getSendProcs(std::vector<int>& sendProcs) const;
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();
00751 
00752     inline void check_version() { fei::utils::version(); }
00753 
00754     void setOwners_lowestSharing();
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     fei::SharedIDs<int>& getSharedIDs_private(int idType);
00772 
00773     void setName(const char* name);
00774 
00775   private:
00776     MPI_Comm comm_;
00777 
00778     std::vector<int> idTypes_;
00779     std::map<int,unsigned> fieldDatabase_;
00780     fei::FieldDofMap<int> fieldDofMap_;
00781     int maxFieldSize_;
00782     std::vector<snl_fei::RecordCollection*> recordCollections_;
00783 
00784     std::map<int, fei::SharedIDs<int> > sharedIDTables_;
00785     std::map<int, fei::comm_map*> ownerPatterns_;
00786     std::map<int, fei::comm_map*> sharerPatterns_;
00787 
00788     bool sharedRecordsSynchronized_;
00789 
00790     snl_fei::PointBlockMap* ptBlkMap_;
00791 
00792     std::vector<int> globalOffsets_;
00793     std::vector<int> globalIDOffsets_;
00794 
00795     bool simpleProblem_;
00796 
00797     int firstLocalOffset_, lastLocalOffset_;
00798 
00799     std::vector<int> eqnNumbers_;
00800 
00801     bool newInitData_;
00802 
00803     std::string name_;
00804     std::string dbgprefix_;
00805     bool checkSharedIDs_;
00806   }; // class fei::VectorSpace
00807 
00808   inline std::vector<int>& VectorSpace::getEqnNumbers()
00809     {
00810       return( eqnNumbers_ );
00811     }
00812 
00813   inline const std::vector<int>& VectorSpace::getEqnNumbers() const
00814     {
00815       return( eqnNumbers_ );
00816     }
00817 
00818   inline snl_fei::PointBlockMap* VectorSpace::getPointBlockMap()
00819     {
00820       return( ptBlkMap_ );
00821     }
00822 
00823   inline const snl_fei::PointBlockMap* VectorSpace::getPointBlockMap() const
00824     {
00825       return( ptBlkMap_ );
00826     }
00827 
00828 } // namespace fei
00829 
00830 #endif // _fei_VectorSpace_hpp_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends