snl_fei_PointBlockMap.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 <snl_fei_PointBlockMap.hpp>
00012 #include <fei_ctg_set.hpp>
00013 #undef fei_file
00014 #define fei_file "snl_fei_PointBlockMap.cpp"
00015 #include <fei_ErrMacros.hpp>
00016 
00017 //----------------------------------------------------------------------------
00018 snl_fei::PointBlockMap::PointBlockMap()
00019   : ptEqns_(NULL),
00020     blkEqns_(NULL),
00021     maxSize_(0),
00022     ptEqualBlk_(false)
00023 {
00024   ptEqns_ = new std::map<int,int>;
00025   blkEqns_ = new std::map<int,std::pair<int,int> >;
00026 }
00027 
00028 //----------------------------------------------------------------------------
00029 snl_fei::PointBlockMap::~PointBlockMap()
00030 {
00031   delete ptEqns_;
00032   delete blkEqns_;
00033 }
00034 
00035 //----------------------------------------------------------------------------
00036 void snl_fei::PointBlockMap::setPtEqualBlk()
00037 {
00038   ptEqualBlk_ = true;
00039 }
00040 
00041 //----------------------------------------------------------------------------
00042 int snl_fei::PointBlockMap::setEqn(int ptEqn, int blkEqn)
00043 {
00044   return( setEqn(ptEqn, blkEqn, 1) );
00045 }
00046 
00047 //----------------------------------------------------------------------------
00048 int snl_fei::PointBlockMap::setEqn(int ptEqn, int blkEqn, int blkSize)
00049 {
00050   if (ptEqualBlk_ == true) {
00051     if (ptEqn != blkEqn) return(-1);
00052     else return(0);
00053   }
00054 
00055   ptEqns_->insert(std::pair<int,int>(ptEqn, blkEqn));
00056 
00057   //check whether blkEqn is already stored in blkEqns_.
00058   //if it is not, then insert it along with the pair ptEqn,blkSize.
00059   //if it is, check whether the already-associated ptEqn is greater than
00060   //the incoming ptEqn, and replace if so.
00061   //We want to have blkEqn mapped to the lower ptEqn.
00062 
00063   std::pair<int, int> newpair;
00064   std::map<int,std::pair<int,int> >::iterator
00065     b_iter = blkEqns_->find(blkEqn);
00066 
00067   if (b_iter == blkEqns_->end()) {
00068     newpair.first = ptEqn;
00069     newpair.second = blkSize;
00070     blkEqns_->insert(std::pair<int,std::pair<int,int> >(blkEqn, newpair));
00071   }
00072   else {
00073     newpair = (*b_iter).second;
00074     if (newpair.first > ptEqn) {
00075       newpair.first = ptEqn;
00076       newpair.second = blkSize;
00077       (*b_iter).second = newpair;
00078     }
00079   }
00080 
00081   return(0);
00082 }
00083 
00084 //----------------------------------------------------------------------------
00085 int snl_fei::PointBlockMap::setBlkEqnSize(int blkEqn, int size)
00086 {
00087   if (ptEqualBlk_ == true) return(0);
00088 
00089   std::pair<int,int> newpair;
00090   std::map<int,std::pair<int,int> >::iterator
00091     b_iter = blkEqns_->find(blkEqn);
00092   if (b_iter == blkEqns_->end()) {
00093     return(-1);
00094   }
00095 
00096   newpair = (*b_iter).second;
00097   newpair.second = size;
00098   (*b_iter).second = newpair;
00099 
00100   if (maxSize_ < size) maxSize_ = size;
00101 
00102   return(0);
00103 }
00104 
00105 //----------------------------------------------------------------------------
00106 int snl_fei::PointBlockMap::getBlkEqnSize(int blkEqn)
00107 {
00108   if (ptEqualBlk_ == true) return(1);
00109 
00110   std::map<int,std::pair<int,int> >::iterator
00111     b_iter = blkEqns_->find(blkEqn);
00112 
00113   if (b_iter != blkEqns_->end()) {
00114     return((*b_iter).second.second);
00115   }
00116 
00117   return(-1);
00118 }
00119 
00120 //----------------------------------------------------------------------------
00121 int snl_fei::PointBlockMap::eqnToBlkEqn(int eqn) const
00122 {
00123   if (ptEqualBlk_ == true) return(eqn);
00124 
00125   int blkEqn = -1;
00126   std::map<int,int>::iterator p_iter = ptEqns_->find(eqn);
00127   if (p_iter != ptEqns_->end()) blkEqn = (*p_iter).second;
00128 
00129   return(blkEqn);
00130 }
00131 
00132 //----------------------------------------------------------------------------
00133 int snl_fei::PointBlockMap::blkEqnToPtEqn(int blkEqn) const
00134 {
00135   if (ptEqualBlk_ == true) return(blkEqn);
00136 
00137   
00138   std::map<int,std::pair<int,int> >::iterator
00139     b_iter = blkEqns_->find(blkEqn);
00140   if (b_iter == blkEqns_->end()) {
00141     return(-1);
00142   }
00143 
00144   return((*b_iter).second.first);
00145 }
00146 
00147 //----------------------------------------------------------------------------
00148 int snl_fei::PointBlockMap::getBlkEqnInfo(int blkEqn, int& ptEqn, int& blkSize)
00149 {
00150   if (ptEqualBlk_ == true) {
00151     ptEqn = blkEqn;
00152     blkSize = 1;
00153     return(0);
00154   }
00155 
00156   std::map<int,std::pair<int,int> >::iterator
00157     b_iter = blkEqns_->find(blkEqn);
00158   if (b_iter == blkEqns_->end()) {
00159     return(-1);
00160   }
00161 
00162   ptEqn = (*b_iter).second.first;
00163   blkSize = (*b_iter).second.second;
00164 
00165   return(0);
00166 }
00167 
00168 //----------------------------------------------------------------------------
00169 int snl_fei::PointBlockMap::getPtEqnInfo(int ptEqn,
00170            int& blkEqn,
00171            int& blkOffset)
00172 {
00173   if (ptEqualBlk_ == true) {
00174     blkEqn = ptEqn;
00175     blkOffset = 0;
00176     return(0);
00177   }
00178 
00179   std::map<int,int>::iterator
00180     p_iter = ptEqns_->find(ptEqn);
00181   if (p_iter == ptEqns_->end()) {
00182     return(-1);
00183   }
00184 
00185   blkEqn = (*p_iter).second;
00186 
00187   std::map<int,std::pair<int,int> >::iterator
00188     b_iter = blkEqns_->find(blkEqn);
00189 
00190   std::pair<int,int> bpair = (*b_iter).second;
00191 
00192   blkOffset = ptEqn - bpair.first;
00193 
00194   return(0);
00195 }
00196 
00197 //----------------------------------------------------------------------------
00198 int snl_fei::PointBlockMap::getBlkEqnOffset(int blkEqn, int eqn)
00199 {
00200   if (ptEqualBlk_ == true) return(0);
00201 
00202   int blkOffset = 0;
00203   int err = getPtEqnInfo(eqn, blkEqn, blkOffset);
00204   if (err != 0) return(err);
00205 
00206   return(blkOffset);
00207 }
00208 
00209 //----------------------------------------------------------------------------
00210 bool snl_fei::PointBlockMap::isExactlyBlkEqn(int ptEqn)
00211 {
00212   if (ptEqualBlk_==true) return(true);
00213 
00214   std::map<int,int>::iterator
00215     p_iter = ptEqns_->find(ptEqn);
00216   if (p_iter == ptEqns_->end()) {
00217     return(false);
00218   }
00219 
00220   return( getBlkEqnOffset((*p_iter).first, ptEqn) == 0 );
00221 }

Generated on Tue Jul 13 09:27:46 2010 for FEI by  doxygen 1.4.7