FEI  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fei_ConnectivityBlock.cpp
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 
11 #include <fei_defs.h>
12 
13 #include <fei_Pattern.hpp>
14 
15 #include <fei_ConnectivityBlock.hpp>
16 
17 #undef fei_file
18 #define fei_file "fei_ConnectivityBlock.cpp"
19 #include <fei_ErrMacros.hpp>
20 
21 //----------------------------------------------------------------------------
23  fei::Pattern* pattern,
24  int numConnectivities)
25  : blockID_(blockID),
26  pattern_(pattern),
27  colPattern_(NULL),
28  isSymmetric_(true),
29  isDiagonal_(false),
30  connIDsOffsetMap_(),
31  connectivityOffsets_(),
32  numRecordsPerConnectivity_(pattern->getNumIDs()),
33  connectivities_(pattern->getNumIDs()*numConnectivities),
34  numRecordsPerColConnectivity_(0),
35  colConnectivities_(),
36  fieldID_(-99),
37  haveFieldID_(false)
38 {
39 }
40 
41 //----------------------------------------------------------------------------
43  fei::Pattern* rowpattern,
44  fei::Pattern* colpattern,
45  int numConnectivities)
46  : blockID_(blockID),
47  pattern_(rowpattern),
48  colPattern_(colpattern),
49  isSymmetric_(false),
50  isDiagonal_(false),
51  connIDsOffsetMap_(),
52  connectivityOffsets_(),
53  numRecordsPerConnectivity_(rowpattern->getNumIDs()),
54  connectivities_(rowpattern->getNumIDs()*numConnectivities),
55  numRecordsPerColConnectivity_(colpattern->getNumIDs()),
56  colConnectivities_(colpattern->getNumIDs()*numConnectivities),
57  fieldID_(-99),
58  haveFieldID_(false)
59 {
60 }
61 
62 //----------------------------------------------------------------------------
64  const int* rowIDs,
65  const int* rowOffsets,
66  bool offsets_are_lengths)
67  : blockID_(-1),
68  pattern_(NULL),
69  colPattern_(NULL),
70  isSymmetric_(false),
71  isDiagonal_(false),
72  connIDsOffsetMap_(),
73  connectivityOffsets_(),
74  numRecordsPerConnectivity_(0),
75  connectivities_(),
76  numRecordsPerColConnectivity_(0),
77  colConnectivities_(),
78  fieldID_(-99),
79  haveFieldID_(false)
80 {
81  connectivities_.resize(numRowIDs);
82  connectivityOffsets_.resize(numRowIDs+1);
83 
84  int clen = 0;
85  if (offsets_are_lengths) {
86  int sum = 0;
87  for(int ii=0; ii<numRowIDs; ++ii) {
88  sum += rowOffsets[ii];
89  }
90  clen = sum;
91  }
92  else clen = rowOffsets[numRowIDs];
93 
94  colConnectivities_.resize(clen);
95 
96  int i;
97  if (offsets_are_lengths) {
98  int offset = 0;
99  for(i=0; i<numRowIDs; ++i) {
100  connIDsOffsetMap_[rowIDs[i]] = i;
101  connectivityOffsets_[i] = offset;
102  offset += rowOffsets[i];
103  }
104  connectivityOffsets_[numRowIDs] = offset;
105  }
106  else {
107  for(i=0; i<numRowIDs; ++i) {
108  connIDsOffsetMap_[rowIDs[i]] = i;
109  connectivityOffsets_[i] = rowOffsets[i];
110  }
111  connectivityOffsets_[numRowIDs] = rowOffsets[numRowIDs];
112  }
113 }
114 
115 //----------------------------------------------------------------------------
117  int numRowIDs,
118  const int* rowIDs,
119  const int* rowOffsets,
120  bool offsets_are_lengths)
121  : blockID_(-1),
122  pattern_(NULL),
123  colPattern_(NULL),
124  isSymmetric_(false),
125  isDiagonal_(false),
126  connIDsOffsetMap_(),
127  connectivityOffsets_(),
128  numRecordsPerConnectivity_(0),
129  connectivities_(),
130  numRecordsPerColConnectivity_(0),
131  colConnectivities_(),
132  fieldID_(fldID),
133  haveFieldID_(true)
134 {
135  connectivities_.resize(numRowIDs);
136  connectivityOffsets_.resize(numRowIDs+1);
137 
138  int clen = 0;
139  if (offsets_are_lengths) {
140  int sum = 0;
141  for(int ii=0; ii<numRowIDs; ++ii) {
142  sum += rowOffsets[ii];
143  }
144  clen = sum;
145  }
146  else clen = rowOffsets[numRowIDs];
147 
148  colConnectivities_.resize(clen);
149 
150  int i;
151  if (offsets_are_lengths) {
152  int offset = 0;
153  for(i=0; i<numRowIDs; ++i) {
154  connIDsOffsetMap_[rowIDs[i]] = i;
155  connectivityOffsets_[i] = offset;
156  offset += rowOffsets[i];
157  }
158  connectivityOffsets_[numRowIDs] = offset;
159  }
160  else {
161  for(i=0; i<numRowIDs+1; ++i) {
162  connIDsOffsetMap_[rowIDs[i]] = i;
163  connectivityOffsets_[i] = rowOffsets[i];
164  }
165  connectivityOffsets_[numRowIDs] = rowOffsets[numRowIDs];
166  }
167 }
168 
169 //----------------------------------------------------------------------------
171 {
172 }
173 
174 //----------------------------------------------------------------------------
176 {
177  std::map<int,int>::const_iterator
178  iter = connIDsOffsetMap_.find(ID);
179  if (iter == connIDsOffsetMap_.end()) {
180  return(NULL);
181  }
182 
183  int ind = iter->second;
184  const int* ptr = &connectivities_[0];
185  return( ptr + ind*numRecordsPerConnectivity_);
186 }
187 
188 //----------------------------------------------------------------------------
190 {
191  std::map<int,int>::const_iterator
192  iter = connIDsOffsetMap_.find(ID);
193  if (iter == connIDsOffsetMap_.end()) {
194  return(NULL);
195  }
196 
197  int ind = iter->second;
198  int* ptr = &connectivities_[0];
199  return( ptr + ind*numRecordsPerConnectivity_);
200 }
201 
202 //----------------------------------------------------------------------------
204 {
205  std::map<int,int>::const_iterator
206  iter = connIDsOffsetMap_.find(ID);
207  if (iter == connIDsOffsetMap_.end()) {
208  return(NULL);
209  }
210 
211  int ind = iter->second;
212  const int* ptr = &colConnectivities_[0];
213  return(ptr+ind*numRecordsPerColConnectivity_);
214 }
215 
216 //----------------------------------------------------------------------------
218 {
219  std::map<int,int>::const_iterator
220  iter = connIDsOffsetMap_.find(ID);
221  if (iter == connIDsOffsetMap_.end()) {
222  return(NULL);
223  }
224 
225  int ind = iter->second;
226  int* ptr = &colConnectivities_[0];
227  return(ptr+ind*numRecordsPerColConnectivity_);
228 }
229 
const int * getRowConnectivity(int ID) const
ConnectivityBlock(int blockID, fei::Pattern *pattern, int numConnectivities)
const int * getColConnectivity(int ID) const