FEI Version of the Day
fei_Pattern.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_Pattern.hpp"
00045 
00046 //-----------------------------------------------------------------------------
00047 fei::Pattern::Pattern(int numIDs, int idType, snl_fei::RecordCollection* recordCollection)
00048   : type_(Pattern::NO_FIELD),
00049     numIDs_(numIDs),
00050     totalNumFields_(0),
00051     numIndices_(numIDs),
00052     data_(),
00053     recordCollections_(numIDs, recordCollection)
00054 {
00055   int i, len = numIDs_*4;
00056   data_.resize(len);
00057   int offset = 0;
00058 
00059   //set idTypes
00060   for(i=0; i<numIDs_; ++i) {
00061     data_[offset++] = idType;
00062   }
00063 
00064   //set numFieldsPerID
00065   for(i=0; i<numIDs_; ++i) {
00066     data_[offset++] = 0;
00067   }
00068 
00069   //set numIndicesPerID
00070   for(i=0; i<numIDs_; ++i) {
00071     data_[offset++] = 1;
00072   }
00073 
00074   //set fieldIDs
00075   for(i=0; i<numIDs_; ++i) {
00076     data_[offset++] = -1;
00077   }
00078 
00079   idTypes_        = &(data_[0]);
00080   numFieldsPerID_ = idTypes_+numIDs_;
00081   numIndicesPerID_= idTypes_+2*numIDs_;
00082   fieldIDs_       = idTypes_+3*numIDs_;
00083 }
00084 
00085 //-----------------------------------------------------------------------------
00086 fei::Pattern::Pattern(int numIDs, int idType, snl_fei::RecordCollection* recordCollection,
00087         int fieldID, int fieldSize)
00088   : type_(Pattern::SIMPLE),
00089     numIDs_(numIDs),
00090     totalNumFields_(numIDs),
00091     numIndices_(0), //numIndices_ to be calculated
00092     data_(),
00093     recordCollections_(numIDs, recordCollection)
00094 {
00095   int i, len = numIDs_*4;
00096   data_.resize(len);
00097   int offset = 0;
00098 
00099   //set idTypes
00100   for(i=0; i<numIDs_; ++i) {
00101     data_[offset++] = idType;
00102   }
00103 
00104   //set numFieldsPerID
00105   for(i=0; i<numIDs_; ++i) {
00106     data_[offset++] = 1;
00107   }
00108 
00109   //set numIndicesPerID
00110   for(i=0; i<numIDs_; ++i) {
00111     data_[offset++] = fieldSize;
00112   }
00113 
00114   //set fieldIDs
00115   for(i=0; i<numIDs_; ++i) {
00116     data_[offset++] = fieldID;
00117   }
00118 
00119   numIndices_ = numIDs_*fieldSize;
00120 
00121   idTypes_        = &(data_[0]);
00122   numFieldsPerID_ = idTypes_+numIDs_;
00123   numIndicesPerID_= idTypes_+2*numIDs_;
00124   fieldIDs_       = idTypes_+3*numIDs_;
00125 }
00126 
00127 //-----------------------------------------------------------------------------
00128 fei::Pattern::Pattern(int numIDs, int idType, snl_fei::RecordCollection* recordCollection,
00129         const int* numFieldsPerID,
00130         const int* fieldIDs,
00131         const int* fieldSizes)
00132   : type_(Pattern::SINGLE_IDTYPE),
00133     numIDs_(numIDs),
00134     totalNumFields_(0), //totalNumFields_ to be calculated
00135     numIndices_(0), //numIndices_ to be calculated
00136     data_(),
00137     recordCollections_(numIDs, recordCollection)
00138 {
00139   int i, len = numIDs_*3;
00140   int maxNumFieldsPerID = 0;
00141   bool oneDistinctFieldID = true;
00142 
00143   for(i=0; i<numIDs; ++i) len += numFieldsPerID[i];
00144   data_.resize(len);
00145 
00146   int offset = 0;
00147   //set idTypes
00148   for(i=0; i<numIDs_; ++i) {
00149     data_[offset++] = idType;
00150   }
00151 
00152   //set numFieldsPerID
00153   for(i=0; i<numIDs; ++i) {
00154     data_[offset++] = numFieldsPerID[i];
00155     if (numFieldsPerID[i] > maxNumFieldsPerID) {
00156       maxNumFieldsPerID = numFieldsPerID[i];
00157     }
00158   }
00159 
00160   //next set numIndicesPerID and fieldIDs
00161   int firstFieldID = 0;
00162   if (numIDs > 0) firstFieldID = fieldIDs[0];
00163 
00164   int fieldIDOffset = offset + numIDs;
00165   for(i=0; i<numIDs; ++i) {
00166     int thisNumIndices = 0;
00167     for(int j=0; j<numFieldsPerID[i]; ++j) {
00168       int fieldSize = fieldSizes[totalNumFields_];
00169       int fieldID = fieldIDs[totalNumFields_++];
00170       if (fieldID != firstFieldID) oneDistinctFieldID = false;
00171       data_[fieldIDOffset++] = fieldID;
00172       numIndices_ += fieldSize;
00173       thisNumIndices += fieldSize;
00174     }
00175     data_[offset+i] = thisNumIndices;
00176   }
00177 
00178   if (oneDistinctFieldID == true && maxNumFieldsPerID < 2) {
00179     type_ = Pattern::SIMPLE;
00180   }
00181 
00182   idTypes_        = &(data_[0]);
00183   numFieldsPerID_ = idTypes_+numIDs_;
00184   numIndicesPerID_= idTypes_+2*numIDs_;
00185   fieldIDs_       = idTypes_+3*numIDs_;
00186 }
00187 
00188 //-----------------------------------------------------------------------------
00189 fei::Pattern::Pattern(int numIDs, const int* idTypes, snl_fei::RecordCollection*const* recordCollections,
00190         const int* numFieldsPerID,
00191         const int* fieldIDs,
00192         const int* fieldSizes)
00193   : type_(Pattern::GENERAL),
00194     numIDs_(numIDs),
00195     totalNumFields_(0), //totalNumFields_ to be calculated
00196     numIndices_(0), //numIndices_ to be calculated
00197     data_(),
00198     recordCollections_(recordCollections, recordCollections+numIDs)
00199 {
00200   int i, len = numIDs*3;
00201   int maxNumFieldsPerID = 0;
00202   bool oneDistinctFieldID = true;
00203   bool oneDistinctIDType = true;
00204 
00205   for(i=0; i<numIDs; ++i) len += numFieldsPerID[i];
00206   data_.resize(len);
00207 
00208   int firstIDType = 0;
00209   if (numIDs > 0) firstIDType = idTypes[0];
00210 
00211   int offset = 0;
00212   //set idTypes
00213   for(i=0; i<numIDs; ++i) {
00214     data_[offset++] = idTypes[i];
00215     if (idTypes[i] != firstIDType) oneDistinctIDType = false;
00216   }
00217 
00218   //set numFieldsPerID
00219   for(i=0; i<numIDs; ++i) {
00220     data_[offset++] = numFieldsPerID[i];
00221     if (numFieldsPerID[i] > maxNumFieldsPerID) {
00222       maxNumFieldsPerID = numFieldsPerID[i];
00223     }
00224   }
00225 
00226   //next set numIndicesPerID and fieldIDs
00227   int firstFieldID = 0;
00228   if (numIDs > 0) firstFieldID = fieldIDs[0];
00229 
00230   int fieldIDOffset = offset + numIDs;
00231   for(i=0; i<numIDs; ++i) {
00232     int thisNumIndices = 0;
00233     for(int j=0; j<numFieldsPerID[i]; ++j) {
00234       int fieldSize = fieldSizes[totalNumFields_];
00235       int fieldID = fieldIDs[totalNumFields_++];
00236       if (fieldID != firstFieldID) oneDistinctFieldID = false;
00237       data_[fieldIDOffset++] = fieldID;
00238       numIndices_ += fieldSize;
00239       thisNumIndices += fieldSize;
00240     }
00241     data_[offset+i] = thisNumIndices;
00242   }
00243 
00244   if (oneDistinctFieldID == true && maxNumFieldsPerID < 2 &&
00245       oneDistinctIDType == true) {
00246     type_ = Pattern::SIMPLE;
00247   }
00248   else if (oneDistinctIDType == true) {
00249     type_ = Pattern::SINGLE_IDTYPE;
00250   }
00251 
00252   idTypes_        = &(data_[0]);
00253   numFieldsPerID_ = idTypes_+numIDs_;
00254   numIndicesPerID_= idTypes_+2*numIDs_;
00255   fieldIDs_       = idTypes_+3*numIDs_;
00256 }
00257 
00258 //-----------------------------------------------------------------------------
00259 fei::Pattern::~Pattern()
00260 {
00261 }
00262 
00263 //-----------------------------------------------------------------------------
00264 bool fei::Pattern::operator==(const fei::Pattern& rhs) const
00265 {
00266   return type_ == rhs.type_ &&
00267          numIDs_ == rhs.numIDs_ &&
00268          totalNumFields_ == rhs.totalNumFields_ &&
00269          numIndices_ == rhs.numIndices_ &&
00270          data_ == rhs.data_;
00271 }
00272 
00273 //-----------------------------------------------------------------------------
00274 bool fei::Pattern::operator!=(const fei::Pattern& rhs) const
00275 {
00276   return !(*this == rhs);
00277 }
00278 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends