FEI Version of the Day
snl_fei_PointBlockMap.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 <snl_fei_PointBlockMap.hpp>
00047 #include <fei_ctg_set.hpp>
00048 #undef fei_file
00049 #define fei_file "snl_fei_PointBlockMap.cpp"
00050 #include <fei_ErrMacros.hpp>
00051 
00052 //----------------------------------------------------------------------------
00053 snl_fei::PointBlockMap::PointBlockMap()
00054   : ptEqns_(NULL),
00055     blkEqns_(NULL),
00056     maxSize_(0),
00057     ptEqualBlk_(false)
00058 {
00059   ptEqns_ = new std::map<int,int>;
00060   blkEqns_ = new std::map<int,std::pair<int,int> >;
00061 }
00062 
00063 //----------------------------------------------------------------------------
00064 snl_fei::PointBlockMap::~PointBlockMap()
00065 {
00066   delete ptEqns_;
00067   delete blkEqns_;
00068 }
00069 
00070 //----------------------------------------------------------------------------
00071 void snl_fei::PointBlockMap::setPtEqualBlk()
00072 {
00073   ptEqualBlk_ = true;
00074 }
00075 
00076 //----------------------------------------------------------------------------
00077 int snl_fei::PointBlockMap::setEqn(int ptEqn, int blkEqn)
00078 {
00079   return( setEqn(ptEqn, blkEqn, 1) );
00080 }
00081 
00082 //----------------------------------------------------------------------------
00083 int snl_fei::PointBlockMap::setEqn(int ptEqn, int blkEqn, int blkSize)
00084 {
00085   if (ptEqualBlk_ == true) {
00086     if (ptEqn != blkEqn) return(-1);
00087     else return(0);
00088   }
00089 
00090   ptEqns_->insert(std::pair<int,int>(ptEqn, blkEqn));
00091 
00092   //check whether blkEqn is already stored in blkEqns_.
00093   //if it is not, then insert it along with the pair ptEqn,blkSize.
00094   //if it is, check whether the already-associated ptEqn is greater than
00095   //the incoming ptEqn, and replace if so.
00096   //We want to have blkEqn mapped to the lower ptEqn.
00097 
00098   std::pair<int, int> newpair;
00099   std::map<int,std::pair<int,int> >::iterator
00100     b_iter = blkEqns_->find(blkEqn);
00101 
00102   if (b_iter == blkEqns_->end()) {
00103     newpair.first = ptEqn;
00104     newpair.second = blkSize;
00105     blkEqns_->insert(std::pair<int,std::pair<int,int> >(blkEqn, newpair));
00106   }
00107   else {
00108     newpair = (*b_iter).second;
00109     if (newpair.first > ptEqn) {
00110       newpair.first = ptEqn;
00111       newpair.second = blkSize;
00112       (*b_iter).second = newpair;
00113     }
00114   }
00115 
00116   return(0);
00117 }
00118 
00119 //----------------------------------------------------------------------------
00120 int snl_fei::PointBlockMap::setBlkEqnSize(int blkEqn, int size)
00121 {
00122   if (ptEqualBlk_ == true) return(0);
00123 
00124   std::pair<int,int> newpair;
00125   std::map<int,std::pair<int,int> >::iterator
00126     b_iter = blkEqns_->find(blkEqn);
00127   if (b_iter == blkEqns_->end()) {
00128     return(-1);
00129   }
00130 
00131   newpair = (*b_iter).second;
00132   newpair.second = size;
00133   (*b_iter).second = newpair;
00134 
00135   if (maxSize_ < size) maxSize_ = size;
00136 
00137   return(0);
00138 }
00139 
00140 //----------------------------------------------------------------------------
00141 int snl_fei::PointBlockMap::getBlkEqnSize(int blkEqn)
00142 {
00143   if (ptEqualBlk_ == true) return(1);
00144 
00145   std::map<int,std::pair<int,int> >::iterator
00146     b_iter = blkEqns_->find(blkEqn);
00147 
00148   if (b_iter != blkEqns_->end()) {
00149     return((*b_iter).second.second);
00150   }
00151 
00152   return(-1);
00153 }
00154 
00155 //----------------------------------------------------------------------------
00156 int snl_fei::PointBlockMap::eqnToBlkEqn(int eqn) const
00157 {
00158   if (ptEqualBlk_ == true) return(eqn);
00159 
00160   int blkEqn = -1;
00161   std::map<int,int>::iterator p_iter = ptEqns_->find(eqn);
00162   if (p_iter != ptEqns_->end()) blkEqn = (*p_iter).second;
00163 
00164   return(blkEqn);
00165 }
00166 
00167 //----------------------------------------------------------------------------
00168 int snl_fei::PointBlockMap::blkEqnToPtEqn(int blkEqn) const
00169 {
00170   if (ptEqualBlk_ == true) return(blkEqn);
00171 
00172   
00173   std::map<int,std::pair<int,int> >::iterator
00174     b_iter = blkEqns_->find(blkEqn);
00175   if (b_iter == blkEqns_->end()) {
00176     return(-1);
00177   }
00178 
00179   return((*b_iter).second.first);
00180 }
00181 
00182 //----------------------------------------------------------------------------
00183 int snl_fei::PointBlockMap::getBlkEqnInfo(int blkEqn, int& ptEqn, int& blkSize)
00184 {
00185   if (ptEqualBlk_ == true) {
00186     ptEqn = blkEqn;
00187     blkSize = 1;
00188     return(0);
00189   }
00190 
00191   std::map<int,std::pair<int,int> >::iterator
00192     b_iter = blkEqns_->find(blkEqn);
00193   if (b_iter == blkEqns_->end()) {
00194     return(-1);
00195   }
00196 
00197   ptEqn = (*b_iter).second.first;
00198   blkSize = (*b_iter).second.second;
00199 
00200   return(0);
00201 }
00202 
00203 //----------------------------------------------------------------------------
00204 int snl_fei::PointBlockMap::getPtEqnInfo(int ptEqn,
00205            int& blkEqn,
00206            int& blkOffset)
00207 {
00208   if (ptEqualBlk_ == true) {
00209     blkEqn = ptEqn;
00210     blkOffset = 0;
00211     return(0);
00212   }
00213 
00214   std::map<int,int>::iterator
00215     p_iter = ptEqns_->find(ptEqn);
00216   if (p_iter == ptEqns_->end()) {
00217     return(-1);
00218   }
00219 
00220   blkEqn = (*p_iter).second;
00221 
00222   std::map<int,std::pair<int,int> >::iterator
00223     b_iter = blkEqns_->find(blkEqn);
00224 
00225   std::pair<int,int> bpair = (*b_iter).second;
00226 
00227   blkOffset = ptEqn - bpair.first;
00228 
00229   return(0);
00230 }
00231 
00232 //----------------------------------------------------------------------------
00233 int snl_fei::PointBlockMap::getBlkEqnOffset(int blkEqn, int eqn)
00234 {
00235   if (ptEqualBlk_ == true) return(0);
00236 
00237   int blkOffset = 0;
00238   int err = getPtEqnInfo(eqn, blkEqn, blkOffset);
00239   if (err != 0) return(err);
00240 
00241   return(blkOffset);
00242 }
00243 
00244 //----------------------------------------------------------------------------
00245 bool snl_fei::PointBlockMap::isExactlyBlkEqn(int ptEqn)
00246 {
00247   if (ptEqualBlk_==true) return(true);
00248 
00249   std::map<int,int>::iterator
00250     p_iter = ptEqns_->find(ptEqn);
00251   if (p_iter == ptEqns_->end()) {
00252     return(false);
00253   }
00254 
00255   return( getBlkEqnOffset((*p_iter).first, ptEqn) == 0 );
00256 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends