FEI Version of the Day
snl_fei_RecordCollection.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 _snl_fei_RecordCollection_hpp_
00045 #define _snl_fei_RecordCollection_hpp_
00046 
00047 #include <fei_iosfwd.hpp>
00048 #include <fei_IndexType.hpp>
00049 #include <fei_Pool_alloc.hpp>
00050 #include <fei_FieldMask.hpp>
00051 #include <fei_Record.hpp>
00052 
00053 #include <map>
00054 #include <vector>
00055 
00056 #undef fei_file
00057 #define fei_file "snl_fei_RecordCollection.hpp"
00058 
00059 #include <fei_ErrMacros.hpp>
00060 
00061 namespace fei {
00062   template<typename T> class SharedIDs;
00063 }
00064 
00065 namespace snl_fei {
00066 
00068   class RecordCollection {
00069   public:
00071     RecordCollection(int localProc);
00072 
00074     RecordCollection(const RecordCollection& src);
00075 
00077     virtual ~RecordCollection();
00078 
00080     void initRecords(int numIDs,
00081          const int* IDs,
00082          std::vector<fei::FieldMask*>& fieldMasks,
00083          int* recordLocalIDs=NULL);
00084 
00086     void initRecords(int fieldID,
00087         int fieldSize,
00088         int numIDs,
00089         const int* IDs,
00090         std::vector<fei::FieldMask*>& fieldMasks,
00091         int* recordLocalIDs=NULL);
00092 
00095     void setOwners_lowestSharing(fei::SharedIDs<int>& sharedIDs);
00096 
00098     size_t getNumRecords() const
00099     {
00100       return( m_records.size() );
00101     }
00102 
00104     fei::IndexType<int,int>& getNativeGlobalToLocalMap()
00105     { return m_global_to_local; }
00106 
00107     const fei::IndexType<int,int>& getNativeGlobalToLocalMap() const
00108     { return m_global_to_local; }
00109 
00110   private:
00114     void syncFrom() const {
00115       if (doesSomeoneHaveMyMap)
00116   m_global_to_local.resyncFromMap(m_global_to_local_map_);
00117     }
00118 
00122     void syncTo() {
00123       if (doesSomeoneHaveMyMap)
00124   m_global_to_local.resyncToMap(m_global_to_local_map_);
00125     }
00126   public:
00127 
00129     FEI_DEPRECATED std::map<int,int>& getGlobalToLocalMap() const ;
00130 
00131     FEI_DEPRECATED const std::map<int,int>& getGlobalToLocalMap() ;
00132 
00134     std::vector<fei::Record<int> >& getRecords()
00135     {
00136       return( m_records );
00137     }
00138 
00140     const std::vector<fei::Record<int> >& getRecords() const
00141     {
00142       return( m_records );
00143     }
00144 
00146     fei::Record<int>* getRecordWithID(int ID);
00147 
00149     const fei::Record<int>* getRecordWithID(int ID) const;
00150 
00151     fei::Record<int>* getRecordWithLocalID(int lid)
00152     { return &m_records[lid]; }
00153 
00154     const fei::Record<int>* getRecordWithLocalID(int lid) const
00155     { return &m_records[lid]; }
00156 
00157     int getLocalID(int global_id) const
00158     {
00159       fei::IndexType<int,int>::const_iterator iter = m_global_to_local.find(global_id);
00160       if (iter == m_global_to_local.end()) {
00161         return -1;
00162       }
00163       return iter->second;
00164     }
00165 
00167     int getGlobalIndex(int ID,
00168         int fieldID,
00169         int fieldSize,
00170         int fieldOffset,
00171         int whichComponentOfField,
00172         const int* eqnNumbers);
00173 
00175     int getGlobalBlkIndex(int ID, int& globalBlkIndex);
00176 
00178     void setDebugOutput(FEI_OSTREAM* dbgOut)
00179     {
00180       dbgOut_ = dbgOut;
00181       debugOutput_ = true;
00182     }
00183 
00184   private:
00185 
00186     std::vector<fei::Record<int> > m_records;
00189     mutable     fei::IndexType<int, int> m_global_to_local;
00191     mutable     std::map<int, int> m_global_to_local_map_;
00193     bool doesSomeoneHaveMyMap;
00194 
00195     int localProc_;
00196 
00197     bool debugOutput_;
00198     FEI_OSTREAM* dbgOut_;
00199   };
00200 
00201 } //namespace snl_fei
00202 
00203 #undef fei_file
00204 
00205 #endif // _snl_fei_RecordCollection_hpp_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends