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     connIDsOffsetMap_(),
00066     connectivityOffsets_(),
00067     numRecordsPerConnectivity_(pattern->getNumIDs()),
00068     connectivities_(pattern->getNumIDs()*numConnectivities),
00069     numRecordsPerColConnectivity_(0),
00070     colConnectivities_(),
00071     fieldID_(-99),
00072     haveFieldID_(false)
00073 {
00074 }
00075 
00076 //----------------------------------------------------------------------------
00077 fei::ConnectivityBlock::ConnectivityBlock(int blockID,
00078               fei::Pattern* rowpattern,
00079               fei::Pattern* colpattern,
00080               int numConnectivities)
00081   : blockID_(blockID),
00082     pattern_(rowpattern),
00083     colPattern_(colpattern),
00084     isSymmetric_(false),
00085     isDiagonal_(false),
00086     connIDsOffsetMap_(),
00087     connectivityOffsets_(),
00088     numRecordsPerConnectivity_(rowpattern->getNumIDs()),
00089     connectivities_(rowpattern->getNumIDs()*numConnectivities),
00090     numRecordsPerColConnectivity_(colpattern->getNumIDs()),
00091     colConnectivities_(colpattern->getNumIDs()*numConnectivities),
00092     fieldID_(-99),
00093     haveFieldID_(false)
00094 {
00095 }
00096 
00097 //----------------------------------------------------------------------------
00098 fei::ConnectivityBlock::ConnectivityBlock(int numRowIDs,
00099               const int* rowIDs,
00100               const int* rowOffsets,
00101               bool offsets_are_lengths)
00102   : blockID_(-1),
00103     pattern_(NULL),
00104     colPattern_(NULL),
00105     isSymmetric_(false),
00106     isDiagonal_(false),
00107     connIDsOffsetMap_(),
00108     connectivityOffsets_(),
00109     numRecordsPerConnectivity_(0),
00110     connectivities_(),
00111     numRecordsPerColConnectivity_(0),
00112     colConnectivities_(),
00113     fieldID_(-99),
00114     haveFieldID_(false)
00115 {
00116   connectivities_.resize(numRowIDs);
00117   connectivityOffsets_.resize(numRowIDs+1);
00118 
00119   int clen = 0;
00120   if (offsets_are_lengths) {
00121     int sum = 0;
00122     for(int ii=0; ii<numRowIDs; ++ii) {
00123       sum += rowOffsets[ii];
00124     }
00125     clen = sum;
00126   }
00127   else clen = rowOffsets[numRowIDs];
00128 
00129   colConnectivities_.resize(clen);
00130 
00131   int i;
00132   if (offsets_are_lengths) {
00133     int offset = 0;
00134     for(i=0; i<numRowIDs; ++i) {
00135       connIDsOffsetMap_[rowIDs[i]] = i;
00136       connectivityOffsets_[i] = offset;
00137       offset += rowOffsets[i];
00138     }
00139     connectivityOffsets_[numRowIDs] = offset;
00140   }
00141   else {
00142     for(i=0; i<numRowIDs; ++i) {
00143       connIDsOffsetMap_[rowIDs[i]] = i;
00144       connectivityOffsets_[i] = rowOffsets[i];
00145     }
00146     connectivityOffsets_[numRowIDs] = rowOffsets[numRowIDs];
00147   }
00148 }
00149 
00150 //----------------------------------------------------------------------------
00151 fei::ConnectivityBlock::ConnectivityBlock(int fldID,
00152               int numRowIDs,
00153               const int* rowIDs,
00154               const int* rowOffsets,
00155               bool offsets_are_lengths)
00156   : blockID_(-1),
00157     pattern_(NULL),
00158     colPattern_(NULL),
00159     isSymmetric_(false),
00160     isDiagonal_(false),
00161     connIDsOffsetMap_(),
00162     connectivityOffsets_(),
00163     numRecordsPerConnectivity_(0),
00164     connectivities_(),
00165     numRecordsPerColConnectivity_(0),
00166     colConnectivities_(),
00167     fieldID_(fldID),
00168     haveFieldID_(true)
00169 {
00170   connectivities_.resize(numRowIDs);
00171   connectivityOffsets_.resize(numRowIDs+1);
00172 
00173   int clen = 0;
00174   if (offsets_are_lengths) {
00175     int sum = 0;
00176     for(int ii=0; ii<numRowIDs; ++ii) {
00177       sum += rowOffsets[ii];
00178     }
00179     clen = sum;
00180   }
00181   else clen = rowOffsets[numRowIDs];
00182 
00183   colConnectivities_.resize(clen);
00184 
00185   int i;
00186   if (offsets_are_lengths) {
00187     int offset = 0;
00188     for(i=0; i<numRowIDs; ++i) {
00189       connIDsOffsetMap_[rowIDs[i]] = i;
00190       connectivityOffsets_[i] = offset;
00191       offset += rowOffsets[i];
00192     }
00193     connectivityOffsets_[numRowIDs] = offset;
00194   }
00195   else {
00196     for(i=0; i<numRowIDs+1; ++i) {
00197       connIDsOffsetMap_[rowIDs[i]] = i;
00198       connectivityOffsets_[i] = rowOffsets[i];
00199     }
00200     connectivityOffsets_[numRowIDs] = rowOffsets[numRowIDs];
00201   }
00202 }
00203 
00204 //----------------------------------------------------------------------------
00205 fei::ConnectivityBlock::~ConnectivityBlock()
00206 {
00207 }
00208 
00209 //----------------------------------------------------------------------------
00210 const int* fei::ConnectivityBlock::getRowConnectivity(int ID) const
00211 {
00212 
00213   MapIntInt::const_iterator
00214     iter = connIDsOffsetMap_.find(ID);
00215   if (iter == connIDsOffsetMap_.end()) {
00216     return(NULL);
00217   }
00218 
00219   int ind = iter->second;
00220   const int* ptr = &connectivities_[0];
00221   return( ptr + ind*numRecordsPerConnectivity_);
00222 }
00223 
00224 //----------------------------------------------------------------------------
00225 int* fei::ConnectivityBlock::getRowConnectivity(int ID)
00226 {
00227   MapIntInt::const_iterator
00228     iter = connIDsOffsetMap_.find(ID);
00229   if (iter == connIDsOffsetMap_.end()) {
00230     return(NULL);
00231   }
00232 
00233   int ind = iter->second;
00234   int* ptr = &connectivities_[0];
00235   return( ptr + ind*numRecordsPerConnectivity_);
00236 }
00237 
00238 //----------------------------------------------------------------------------
00239 const int* fei::ConnectivityBlock::getColConnectivity(int ID) const
00240 {
00241   MapIntInt::const_iterator
00242     iter = connIDsOffsetMap_.find(ID);
00243   if (iter == connIDsOffsetMap_.end()) {
00244     return(NULL);
00245   }
00246 
00247   int ind = iter->second;
00248   const int* ptr = &colConnectivities_[0];
00249   return(ptr+ind*numRecordsPerColConnectivity_);
00250 }
00251 
00252 //----------------------------------------------------------------------------
00253 int* fei::ConnectivityBlock::getColConnectivity(int ID)
00254 {
00255   MapIntInt::const_iterator
00256     iter = connIDsOffsetMap_.find(ID);
00257   if (iter == connIDsOffsetMap_.end()) {
00258     return(NULL);
00259   }
00260 
00261   int ind = iter->second;
00262   int* ptr = &colConnectivities_[0];
00263   return(ptr+ind*numRecordsPerColConnectivity_);
00264 }
00265 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends