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