FEI Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
snl_fei_PointBlockMap.cpp
Go to the documentation of this file.
1 /*--------------------------------------------------------------------*/
2 /* Copyright 2005 Sandia Corporation. */
3 /* Under the terms of Contract DE-AC04-94AL85000, there is a */
4 /* non-exclusive license for use of this work by or on behalf */
5 /* of the U.S. Government. Export of this program may require */
6 /* a license from the United States Government. */
7 /*--------------------------------------------------------------------*/
8 
9 #include <fei_macros.hpp>
10 
12 #include <fei_ctg_set.hpp>
13 #undef fei_file
14 #define fei_file "snl_fei_PointBlockMap.cpp"
15 #include <fei_ErrMacros.hpp>
16 
17 //----------------------------------------------------------------------------
19  : ptEqns_(NULL),
20  blkEqns_(NULL),
21  maxSize_(0),
22  ptEqualBlk_(false)
23 {
24  ptEqns_ = new std::map<int,int>;
25  blkEqns_ = new std::map<int,std::pair<int,int> >;
26 }
27 
28 //----------------------------------------------------------------------------
30 {
31  delete ptEqns_;
32  delete blkEqns_;
33 }
34 
35 //----------------------------------------------------------------------------
37 {
38  ptEqualBlk_ = true;
39 }
40 
41 //----------------------------------------------------------------------------
42 int snl_fei::PointBlockMap::setEqn(int ptEqn, int blkEqn)
43 {
44  return( setEqn(ptEqn, blkEqn, 1) );
45 }
46 
47 //----------------------------------------------------------------------------
48 int snl_fei::PointBlockMap::setEqn(int ptEqn, int blkEqn, int blkSize)
49 {
50  if (ptEqualBlk_ == true) {
51  if (ptEqn != blkEqn) return(-1);
52  else return(0);
53  }
54 
55  ptEqns_->insert(std::pair<int,int>(ptEqn, blkEqn));
56 
57  //check whether blkEqn is already stored in blkEqns_.
58  //if it is not, then insert it along with the pair ptEqn,blkSize.
59  //if it is, check whether the already-associated ptEqn is greater than
60  //the incoming ptEqn, and replace if so.
61  //We want to have blkEqn mapped to the lower ptEqn.
62 
63  std::pair<int, int> newpair;
64  std::map<int,std::pair<int,int> >::iterator
65  b_iter = blkEqns_->find(blkEqn);
66 
67  if (b_iter == blkEqns_->end()) {
68  newpair.first = ptEqn;
69  newpair.second = blkSize;
70  blkEqns_->insert(std::pair<int,std::pair<int,int> >(blkEqn, newpair));
71  }
72  else {
73  newpair = (*b_iter).second;
74  if (newpair.first > ptEqn) {
75  newpair.first = ptEqn;
76  newpair.second = blkSize;
77  (*b_iter).second = newpair;
78  }
79  }
80 
81  return(0);
82 }
83 
84 //----------------------------------------------------------------------------
85 int snl_fei::PointBlockMap::setBlkEqnSize(int blkEqn, int size)
86 {
87  if (ptEqualBlk_ == true) return(0);
88 
89  std::pair<int,int> newpair;
90  std::map<int,std::pair<int,int> >::iterator
91  b_iter = blkEqns_->find(blkEqn);
92  if (b_iter == blkEqns_->end()) {
93  return(-1);
94  }
95 
96  newpair = (*b_iter).second;
97  newpair.second = size;
98  (*b_iter).second = newpair;
99 
100  if (maxSize_ < size) maxSize_ = size;
101 
102  return(0);
103 }
104 
105 //----------------------------------------------------------------------------
107 {
108  if (ptEqualBlk_ == true) return(1);
109 
110  std::map<int,std::pair<int,int> >::iterator
111  b_iter = blkEqns_->find(blkEqn);
112 
113  if (b_iter != blkEqns_->end()) {
114  return((*b_iter).second.second);
115  }
116 
117  return(-1);
118 }
119 
120 //----------------------------------------------------------------------------
122 {
123  if (ptEqualBlk_ == true) return(eqn);
124 
125  int blkEqn = -1;
126  std::map<int,int>::iterator p_iter = ptEqns_->find(eqn);
127  if (p_iter != ptEqns_->end()) blkEqn = (*p_iter).second;
128 
129  return(blkEqn);
130 }
131 
132 //----------------------------------------------------------------------------
134 {
135  if (ptEqualBlk_ == true) return(blkEqn);
136 
137 
138  std::map<int,std::pair<int,int> >::iterator
139  b_iter = blkEqns_->find(blkEqn);
140  if (b_iter == blkEqns_->end()) {
141  return(-1);
142  }
143 
144  return((*b_iter).second.first);
145 }
146 
147 //----------------------------------------------------------------------------
148 int snl_fei::PointBlockMap::getBlkEqnInfo(int blkEqn, int& ptEqn, int& blkSize)
149 {
150  if (ptEqualBlk_ == true) {
151  ptEqn = blkEqn;
152  blkSize = 1;
153  return(0);
154  }
155 
156  std::map<int,std::pair<int,int> >::iterator
157  b_iter = blkEqns_->find(blkEqn);
158  if (b_iter == blkEqns_->end()) {
159  return(-1);
160  }
161 
162  ptEqn = (*b_iter).second.first;
163  blkSize = (*b_iter).second.second;
164 
165  return(0);
166 }
167 
168 //----------------------------------------------------------------------------
170  int& blkEqn,
171  int& blkOffset)
172 {
173  if (ptEqualBlk_ == true) {
174  blkEqn = ptEqn;
175  blkOffset = 0;
176  return(0);
177  }
178 
179  std::map<int,int>::iterator
180  p_iter = ptEqns_->find(ptEqn);
181  if (p_iter == ptEqns_->end()) {
182  return(-1);
183  }
184 
185  blkEqn = (*p_iter).second;
186 
187  std::map<int,std::pair<int,int> >::iterator
188  b_iter = blkEqns_->find(blkEqn);
189 
190  std::pair<int,int> bpair = (*b_iter).second;
191 
192  blkOffset = ptEqn - bpair.first;
193 
194  return(0);
195 }
196 
197 //----------------------------------------------------------------------------
199 {
200  if (ptEqualBlk_ == true) return(0);
201 
202  int blkOffset = 0;
203  int err = getPtEqnInfo(eqn, blkEqn, blkOffset);
204  if (err != 0) return(err);
205 
206  return(blkOffset);
207 }
208 
209 //----------------------------------------------------------------------------
211 {
212  if (ptEqualBlk_==true) return(true);
213 
214  std::map<int,int>::iterator
215  p_iter = ptEqns_->find(ptEqn);
216  if (p_iter == ptEqns_->end()) {
217  return(false);
218  }
219 
220  return( getBlkEqnOffset((*p_iter).first, ptEqn) == 0 );
221 }
std::map< int, int > * ptEqns_
int setBlkEqnSize(int blkEqn, int size)
int getBlkEqnOffset(int blkEqn, int ptEqn)
int setEqn(int ptEqn, int blkEqn)
int eqnToBlkEqn(int eqn) const
std::map< int, std::pair< int, int > > * blkEqns_
int getPtEqnInfo(int ptEqn, int &blkEqn, int &blkOffset)
int blkEqnToPtEqn(int blkEqn) const
int getBlkEqnInfo(int blkEqn, int &ptEqn, int &blkSize)