FEI Version of the Day
fei_ConnectivityBlock.cpp
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 #include <fei_macros.hpp>
00045 
00046 #include <fei_defs.h>
00047 
00048 #include <fei_Pattern.hpp>
00049 
00050 #include <fei_ConnectivityBlock.hpp>
00051 
00052 #undef fei_file
00053 #define fei_file "fei_ConnectivityBlock.cpp"
00054 #include <fei_ErrMacros.hpp>
00055 
00056 //----------------------------------------------------------------------------
00057 fei::ConnectivityBlock::ConnectivityBlock(int blockID,
00058               fei::Pattern* pattern,
00059               int numConnectivities)
00060   : blockID_(blockID),
00061     pattern_(pattern),
00062     colPattern_(NULL),
00063     isSymmetric_(true),
00064     isDiagonal_(false),
00065     doesSomeoneHaveMyMap(false),
00066     connIDsOffsetMap_(),
00067     connectivityOffsets_(),
00068     numRecordsPerConnectivity_(pattern->getNumIDs()),
00069     connectivities_(pattern->getNumIDs()*numConnectivities),
00070     numRecordsPerColConnectivity_(0),
00071     colConnectivities_(),
00072     fieldID_(-99),
00073     haveFieldID_(false)
00074 {
00075 }
00076 
00077 //----------------------------------------------------------------------------
00078 fei::ConnectivityBlock::ConnectivityBlock(int blockID,
00079               fei::Pattern* rowpattern,
00080               fei::Pattern* colpattern,
00081               int numConnectivities)
00082   : blockID_(blockID),
00083     pattern_(rowpattern),
00084     colPattern_(colpattern),
00085     isSymmetric_(false),
00086     isDiagonal_(false),
00087     doesSomeoneHaveMyMap(false),
00088     connIDsOffsetMap_(),
00089     connectivityOffsets_(),
00090     numRecordsPerConnectivity_(rowpattern->getNumIDs()),
00091     connectivities_(rowpattern->getNumIDs()*numConnectivities),
00092     numRecordsPerColConnectivity_(colpattern->getNumIDs()),
00093     colConnectivities_(colpattern->getNumIDs()*numConnectivities),
00094     fieldID_(-99),
00095     haveFieldID_(false)
00096 {
00097 }
00098 
00099 //----------------------------------------------------------------------------
00100 fei::ConnectivityBlock::ConnectivityBlock(int numRowIDs,
00101               const int* rowIDs,
00102               const int* rowOffsets,
00103               bool offsets_are_lengths)
00104   : blockID_(-1),
00105     pattern_(NULL),
00106     colPattern_(NULL),
00107     isSymmetric_(false),
00108     isDiagonal_(false),
00109     doesSomeoneHaveMyMap(false),
00110     connIDsOffsetMap_(),
00111     connectivityOffsets_(),
00112     numRecordsPerConnectivity_(0),
00113     connectivities_(),
00114     numRecordsPerColConnectivity_(0),
00115     colConnectivities_(),
00116     fieldID_(-99),
00117     haveFieldID_(false)
00118 {
00119   connectivities_.resize(numRowIDs);
00120   connectivityOffsets_.resize(numRowIDs+1);
00121 
00122   int clen = 0;
00123   if (offsets_are_lengths) {
00124     int sum = 0;
00125     for(int ii=0; ii<numRowIDs; ++ii) {
00126       sum += rowOffsets[ii];
00127     }
00128     clen = sum;
00129   }
00130   else clen = rowOffsets[numRowIDs];
00131 
00132   colConnectivities_.resize(clen);
00133 
00134   syncFrom();
00135   int i;
00136   if (offsets_are_lengths) {
00137     int offset = 0;
00138     for(i=0; i<numRowIDs; ++i) {
00139       connIDsOffsetMap_[rowIDs[i]] = i;
00140       connectivityOffsets_[i] = offset;
00141       offset += rowOffsets[i];
00142     }
00143     connectivityOffsets_[numRowIDs] = offset;
00144   }
00145   else {
00146     for(i=0; i<numRowIDs; ++i) {
00147       connIDsOffsetMap_[rowIDs[i]] = i;
00148       connectivityOffsets_[i] = rowOffsets[i];
00149     }
00150     connectivityOffsets_[numRowIDs] = rowOffsets[numRowIDs];
00151   }
00152   syncTo();
00153 }
00154 
00155 //----------------------------------------------------------------------------
00156 fei::ConnectivityBlock::ConnectivityBlock(int fldID,
00157               int numRowIDs,
00158               const int* rowIDs,
00159               const int* rowOffsets,
00160               bool offsets_are_lengths)
00161   : blockID_(-1),
00162     pattern_(NULL),
00163     colPattern_(NULL),
00164     isSymmetric_(false),
00165     isDiagonal_(false),
00166     doesSomeoneHaveMyMap(false),
00167     connIDsOffsetMap_(),
00168     connectivityOffsets_(),
00169     numRecordsPerConnectivity_(0),
00170     connectivities_(),
00171     numRecordsPerColConnectivity_(0),
00172     colConnectivities_(),
00173     fieldID_(fldID),
00174     haveFieldID_(true)
00175 {
00176   connectivities_.resize(numRowIDs);
00177   connectivityOffsets_.resize(numRowIDs+1);
00178 
00179   int clen = 0;
00180   if (offsets_are_lengths) {
00181     int sum = 0;
00182     for(int ii=0; ii<numRowIDs; ++ii) {
00183       sum += rowOffsets[ii];
00184     }
00185     clen = sum;
00186   }
00187   else clen = rowOffsets[numRowIDs];
00188 
00189   colConnectivities_.resize(clen);
00190 
00191   syncFrom();
00192   int i;
00193   if (offsets_are_lengths) {
00194     int offset = 0;
00195     for(i=0; i<numRowIDs; ++i) {
00196       connIDsOffsetMap_[rowIDs[i]] = i;
00197       connectivityOffsets_[i] = offset;
00198       offset += rowOffsets[i];
00199     }
00200     connectivityOffsets_[numRowIDs] = offset;
00201   }
00202   else {
00203     for(i=0; i<numRowIDs+1; ++i) {
00204       connIDsOffsetMap_[rowIDs[i]] = i;
00205       connectivityOffsets_[i] = rowOffsets[i];
00206     }
00207     connectivityOffsets_[numRowIDs] = rowOffsets[numRowIDs];
00208   }
00209   syncTo();
00210 }
00211 
00212 //----------------------------------------------------------------------------
00213 fei::ConnectivityBlock::~ConnectivityBlock()
00214 {
00215 }
00216 
00217 //----------------------------------------------------------------------------
00218 const int* fei::ConnectivityBlock::getRowConnectivity(int ID) const
00219 {
00220 
00221   syncFrom();
00222   IndexType<int,int>::const_iterator
00223     iter = connIDsOffsetMap_.find(ID);
00224   if (iter == connIDsOffsetMap_.end()) {
00225     return(NULL);
00226   }
00227 
00228   int ind = iter->second;
00229   const int* ptr = &connectivities_[0];
00230   return( ptr + ind*numRecordsPerConnectivity_);
00231 }
00232 
00233 //----------------------------------------------------------------------------
00234 int* fei::ConnectivityBlock::getRowConnectivity(int ID)
00235 {
00236   syncFrom();
00237   IndexType<int,int>::const_iterator
00238     iter = connIDsOffsetMap_.find(ID);
00239   if (iter == connIDsOffsetMap_.end()) {
00240     return(NULL);
00241   }
00242 
00243   int ind = iter->second;
00244   int* ptr = &connectivities_[0];
00245   return( ptr + ind*numRecordsPerConnectivity_);
00246 }
00247 
00248 //----------------------------------------------------------------------------
00249 const int* fei::ConnectivityBlock::getColConnectivity(int ID) const
00250 {
00251   syncFrom();
00252   IndexType<int,int>::const_iterator
00253     iter = connIDsOffsetMap_.find(ID);
00254   if (iter == connIDsOffsetMap_.end()) {
00255     return(NULL);
00256   }
00257 
00258   int ind = iter->second;
00259   const int* ptr = &colConnectivities_[0];
00260   return(ptr+ind*numRecordsPerColConnectivity_);
00261 }
00262 
00263 //----------------------------------------------------------------------------
00264 int* fei::ConnectivityBlock::getColConnectivity(int ID)
00265 {
00266   syncFrom();
00267   IndexType<int,int>::const_iterator
00268     iter = connIDsOffsetMap_.find(ID);
00269   if (iter == connIDsOffsetMap_.end()) {
00270     return(NULL);
00271   }
00272 
00273   int ind = iter->second;
00274   int* ptr = &colConnectivities_[0];
00275   return(ptr+ind*numRecordsPerColConnectivity_);
00276 }
00277 
00278 //----------------------------------------------------------------------------
00279 const std::map<int,int>& fei::ConnectivityBlock::getConnectivityIDs() const {
00280   if (connIDsOffsetMap_.isStdMap()) 
00281     return(connIDsOffsetMap_.asMap(connIDsOffsetMap_map_));
00282   connIDsOffsetMap_.resyncToMap(connIDsOffsetMap_map_);
00283   return(connIDsOffsetMap_map_ );
00284 }
00285 
00286 //----------------------------------------------------------------------------
00287 std::map<int,int>& fei::ConnectivityBlock::getConnectivityIDs() {
00288   if (connIDsOffsetMap_.isStdMap()) 
00289     return(connIDsOffsetMap_.asMap(connIDsOffsetMap_map_));
00290       
00291   // This will cause a lot of work once this is set
00292   doesSomeoneHaveMyMap=true;
00293 
00294   connIDsOffsetMap_.resyncToMap(connIDsOffsetMap_map_);
00295   return(connIDsOffsetMap_map_ );
00296 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends