fei_ConnectivityBlock.cpp

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 #include <fei_macros.hpp>
00010 
00011 #include <fei_defs.h>
00012 
00013 #include <fei_Record.hpp>
00014 #include <fei_Pattern.hpp>
00015 
00016 #include <fei_ConnectivityBlock.hpp>
00017 
00018 #undef fei_file
00019 #define fei_file "fei_ConnectivityBlock.cpp"
00020 #include <fei_ErrMacros.hpp>
00021 
00022 //----------------------------------------------------------------------------
00023 fei::ConnectivityBlock::ConnectivityBlock(int blockID,
00024               fei::Pattern* pattern,
00025               int numConnectivities)
00026   : blockID_(blockID),
00027     pattern_(pattern),
00028     colPattern_(NULL),
00029     isSymmetric_(true),
00030     isDiagonal_(false),
00031     connIDsOffsetMap_(),
00032     connectivityOffsets_(),
00033     numRecordsPerConnectivity_(pattern->getNumIDs()),
00034     connectivities_(pattern->getNumIDs()*numConnectivities),
00035     numRecordsPerColConnectivity_(0),
00036     colConnectivities_(),
00037     fieldID_(-99),
00038     haveFieldID_(false)
00039 {
00040 }
00041 
00042 //----------------------------------------------------------------------------
00043 fei::ConnectivityBlock::ConnectivityBlock(int blockID,
00044               fei::Pattern* rowpattern,
00045               fei::Pattern* colpattern,
00046               int numConnectivities)
00047   : blockID_(blockID),
00048     pattern_(rowpattern),
00049     colPattern_(colpattern),
00050     isSymmetric_(false),
00051     isDiagonal_(false),
00052     connIDsOffsetMap_(),
00053     connectivityOffsets_(),
00054     numRecordsPerConnectivity_(rowpattern->getNumIDs()),
00055     connectivities_(rowpattern->getNumIDs()*numConnectivities),
00056     numRecordsPerColConnectivity_(colpattern->getNumIDs()),
00057     colConnectivities_(colpattern->getNumIDs()*numConnectivities),
00058     fieldID_(-99),
00059     haveFieldID_(false)
00060 {
00061 }
00062 
00063 //----------------------------------------------------------------------------
00064 fei::ConnectivityBlock::ConnectivityBlock(int numRowIDs,
00065               const int* rowIDs,
00066               const int* rowOffsets,
00067               bool offsets_are_lengths)
00068   : blockID_(-1),
00069     pattern_(NULL),
00070     colPattern_(NULL),
00071     isSymmetric_(false),
00072     isDiagonal_(false),
00073     connIDsOffsetMap_(),
00074     connectivityOffsets_(),
00075     numRecordsPerConnectivity_(0),
00076     connectivities_(),
00077     numRecordsPerColConnectivity_(0),
00078     colConnectivities_(),
00079     fieldID_(-99),
00080     haveFieldID_(false)
00081 {
00082   connectivities_.resize(numRowIDs);
00083   connectivityOffsets_.resize(numRowIDs+1);
00084 
00085   int clen = 0;
00086   if (offsets_are_lengths) {
00087     int sum = 0;
00088     for(int ii=0; ii<numRowIDs; ++ii) {
00089       sum += rowOffsets[ii];
00090     }
00091     clen = sum;
00092   }
00093   else clen = rowOffsets[numRowIDs];
00094 
00095   colConnectivities_.resize(clen);
00096 
00097   int i;
00098   if (offsets_are_lengths) {
00099     int offset = 0;
00100     for(i=0; i<numRowIDs; ++i) {
00101       connIDsOffsetMap_[rowIDs[i]] = i;
00102       connectivityOffsets_[i] = offset;
00103       offset += rowOffsets[i];
00104     }
00105     connectivityOffsets_[numRowIDs] = offset;
00106   }
00107   else {
00108     for(i=0; i<numRowIDs; ++i) {
00109       connIDsOffsetMap_[rowIDs[i]] = i;
00110       connectivityOffsets_[i] = rowOffsets[i];
00111     }
00112     connectivityOffsets_[numRowIDs] = rowOffsets[numRowIDs];
00113   }
00114 }
00115 
00116 //----------------------------------------------------------------------------
00117 fei::ConnectivityBlock::ConnectivityBlock(int fldID,
00118               int numRowIDs,
00119               const int* rowIDs,
00120               const int* rowOffsets,
00121               bool offsets_are_lengths)
00122   : blockID_(-1),
00123     pattern_(NULL),
00124     colPattern_(NULL),
00125     isSymmetric_(false),
00126     isDiagonal_(false),
00127     connIDsOffsetMap_(),
00128     connectivityOffsets_(),
00129     numRecordsPerConnectivity_(0),
00130     connectivities_(),
00131     numRecordsPerColConnectivity_(0),
00132     colConnectivities_(),
00133     fieldID_(fldID),
00134     haveFieldID_(true)
00135 {
00136   connectivities_.resize(numRowIDs);
00137   connectivityOffsets_.resize(numRowIDs+1);
00138 
00139   int clen = 0;
00140   if (offsets_are_lengths) {
00141     int sum = 0;
00142     for(int ii=0; ii<numRowIDs; ++ii) {
00143       sum += rowOffsets[ii];
00144     }
00145     clen = sum;
00146   }
00147   else clen = rowOffsets[numRowIDs];
00148 
00149   colConnectivities_.resize(clen);
00150 
00151   int i;
00152   if (offsets_are_lengths) {
00153     int offset = 0;
00154     for(i=0; i<numRowIDs; ++i) {
00155       connIDsOffsetMap_[rowIDs[i]] = i;
00156       connectivityOffsets_[i] = offset;
00157       offset += rowOffsets[i];
00158     }
00159     connectivityOffsets_[numRowIDs] = offset;
00160   }
00161   else {
00162     for(i=0; i<numRowIDs+1; ++i) {
00163       connIDsOffsetMap_[rowIDs[i]] = i;
00164       connectivityOffsets_[i] = rowOffsets[i];
00165     }
00166     connectivityOffsets_[numRowIDs] = rowOffsets[numRowIDs];
00167   }
00168 }
00169 
00170 //----------------------------------------------------------------------------
00171 fei::ConnectivityBlock::~ConnectivityBlock()
00172 {
00173 }
00174 
00175 //----------------------------------------------------------------------------
00176 const fei::Record<int>*const* fei::ConnectivityBlock::getRowConnectivity(int ID) const
00177 {
00178   std::map<int,int>::const_iterator
00179     iter = connIDsOffsetMap_.find(ID);
00180   if (iter == connIDsOffsetMap_.end()) {
00181     return(NULL);
00182   }
00183 
00184   int ind = iter->second;
00185   const Record<int>*const* ptr = &connectivities_[0];
00186   return( ptr + ind*numRecordsPerConnectivity_);
00187 }
00188 
00189 //----------------------------------------------------------------------------
00190 fei::Record<int>** fei::ConnectivityBlock::getRowConnectivity(int ID)
00191 {
00192   std::map<int,int>::const_iterator
00193     iter = connIDsOffsetMap_.find(ID);
00194   if (iter == connIDsOffsetMap_.end()) {
00195     return(NULL);
00196   }
00197 
00198   int ind = iter->second;
00199   Record<int>** ptr = &connectivities_[0];
00200   return( ptr + ind*numRecordsPerConnectivity_);
00201 }
00202 
00203 //----------------------------------------------------------------------------
00204 const fei::Record<int>*const* fei::ConnectivityBlock::getColConnectivity(int ID) const
00205 {
00206   std::map<int,int>::const_iterator
00207     iter = connIDsOffsetMap_.find(ID);
00208   if (iter == connIDsOffsetMap_.end()) {
00209     return(NULL);
00210   }
00211 
00212   int ind = iter->second;
00213   const Record<int>*const* ptr = &colConnectivities_[0];
00214   return(ptr+ind*numRecordsPerColConnectivity_);
00215 }
00216 
00217 //----------------------------------------------------------------------------
00218 fei::Record<int>** fei::ConnectivityBlock::getColConnectivity(int ID)
00219 {
00220   std::map<int,int>::const_iterator
00221     iter = connIDsOffsetMap_.find(ID);
00222   if (iter == connIDsOffsetMap_.end()) {
00223     return(NULL);
00224   }
00225 
00226   int ind = iter->second;
00227   Record<int>** ptr = &colConnectivities_[0];
00228   return(ptr+ind*numRecordsPerColConnectivity_);
00229 }
00230 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends
Generated on Wed Apr 13 10:08:23 2011 for FEI by  doxygen 1.6.3