FEI Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fei_Pattern.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_Pattern.hpp"
10 
11 //-----------------------------------------------------------------------------
12 fei::Pattern::Pattern(int numIDs, int idType, snl_fei::RecordCollection* recordCollection)
13  : type_(Pattern::NO_FIELD),
14  numIDs_(numIDs),
15  totalNumFields_(0),
16  numIndices_(numIDs),
17  data_(),
18  recordCollections_(numIDs, recordCollection)
19 {
20  int i, len = numIDs_*4;
21  data_.resize(len);
22  int offset = 0;
23 
24  //set idTypes
25  for(i=0; i<numIDs_; ++i) {
26  data_[offset++] = idType;
27  }
28 
29  //set numFieldsPerID
30  for(i=0; i<numIDs_; ++i) {
31  data_[offset++] = 0;
32  }
33 
34  //set numIndicesPerID
35  for(i=0; i<numIDs_; ++i) {
36  data_[offset++] = 1;
37  }
38 
39  //set fieldIDs
40  for(i=0; i<numIDs_; ++i) {
41  data_[offset++] = -1;
42  }
43 
44  idTypes_ = &(data_[0]);
48 }
49 
50 //-----------------------------------------------------------------------------
51 fei::Pattern::Pattern(int numIDs, int idType, snl_fei::RecordCollection* recordCollection,
52  int fieldID, int fieldSize)
53  : type_(Pattern::SIMPLE),
54  numIDs_(numIDs),
55  totalNumFields_(numIDs),
56  numIndices_(0), //numIndices_ to be calculated
57  data_(),
58  recordCollections_(numIDs, recordCollection)
59 {
60  int i, len = numIDs_*4;
61  data_.resize(len);
62  int offset = 0;
63 
64  //set idTypes
65  for(i=0; i<numIDs_; ++i) {
66  data_[offset++] = idType;
67  }
68 
69  //set numFieldsPerID
70  for(i=0; i<numIDs_; ++i) {
71  data_[offset++] = 1;
72  }
73 
74  //set numIndicesPerID
75  for(i=0; i<numIDs_; ++i) {
76  data_[offset++] = fieldSize;
77  }
78 
79  //set fieldIDs
80  for(i=0; i<numIDs_; ++i) {
81  data_[offset++] = fieldID;
82  }
83 
84  numIndices_ = numIDs_*fieldSize;
85 
86  idTypes_ = &(data_[0]);
90 }
91 
92 //-----------------------------------------------------------------------------
93 fei::Pattern::Pattern(int numIDs, int idType, snl_fei::RecordCollection* recordCollection,
94  const int* numFieldsPerID,
95  const int* fieldIDs,
96  const int* fieldSizes)
97  : type_(Pattern::SINGLE_IDTYPE),
98  numIDs_(numIDs),
99  totalNumFields_(0), //totalNumFields_ to be calculated
100  numIndices_(0), //numIndices_ to be calculated
101  data_(),
102  recordCollections_(numIDs, recordCollection)
103 {
104  int i, len = numIDs_*3;
105  int maxNumFieldsPerID = 0;
106  bool oneDistinctFieldID = true;
107 
108  for(i=0; i<numIDs; ++i) len += numFieldsPerID[i];
109  data_.resize(len);
110 
111  int offset = 0;
112  //set idTypes
113  for(i=0; i<numIDs_; ++i) {
114  data_[offset++] = idType;
115  }
116 
117  //set numFieldsPerID
118  for(i=0; i<numIDs; ++i) {
119  data_[offset++] = numFieldsPerID[i];
120  if (numFieldsPerID[i] > maxNumFieldsPerID) {
121  maxNumFieldsPerID = numFieldsPerID[i];
122  }
123  }
124 
125  //next set numIndicesPerID and fieldIDs
126  int firstFieldID = 0;
127  if (numIDs > 0) firstFieldID = fieldIDs[0];
128 
129  int fieldIDOffset = offset + numIDs;
130  for(i=0; i<numIDs; ++i) {
131  int thisNumIndices = 0;
132  for(int j=0; j<numFieldsPerID[i]; ++j) {
133  int fieldSize = fieldSizes[totalNumFields_];
134  int fieldID = fieldIDs[totalNumFields_++];
135  if (fieldID != firstFieldID) oneDistinctFieldID = false;
136  data_[fieldIDOffset++] = fieldID;
137  numIndices_ += fieldSize;
138  thisNumIndices += fieldSize;
139  }
140  data_[offset+i] = thisNumIndices;
141  }
142 
143  if (oneDistinctFieldID == true && maxNumFieldsPerID < 2) {
145  }
146 
147  idTypes_ = &(data_[0]);
151 }
152 
153 //-----------------------------------------------------------------------------
154 fei::Pattern::Pattern(int numIDs, const int* idTypes, snl_fei::RecordCollection*const* recordCollections,
155  const int* numFieldsPerID,
156  const int* fieldIDs,
157  const int* fieldSizes)
158  : type_(Pattern::GENERAL),
159  numIDs_(numIDs),
160  totalNumFields_(0), //totalNumFields_ to be calculated
161  numIndices_(0), //numIndices_ to be calculated
162  data_(),
163  recordCollections_(recordCollections, recordCollections+numIDs)
164 {
165  int i, len = numIDs*3;
166  int maxNumFieldsPerID = 0;
167  bool oneDistinctFieldID = true;
168  bool oneDistinctIDType = true;
169 
170  for(i=0; i<numIDs; ++i) len += numFieldsPerID[i];
171  data_.resize(len);
172 
173  int firstIDType = 0;
174  if (numIDs > 0) firstIDType = idTypes[0];
175 
176  int offset = 0;
177  //set idTypes
178  for(i=0; i<numIDs; ++i) {
179  data_[offset++] = idTypes[i];
180  if (idTypes[i] != firstIDType) oneDistinctIDType = false;
181  }
182 
183  //set numFieldsPerID
184  for(i=0; i<numIDs; ++i) {
185  data_[offset++] = numFieldsPerID[i];
186  if (numFieldsPerID[i] > maxNumFieldsPerID) {
187  maxNumFieldsPerID = numFieldsPerID[i];
188  }
189  }
190 
191  //next set numIndicesPerID and fieldIDs
192  int firstFieldID = 0;
193  if (numIDs > 0) firstFieldID = fieldIDs[0];
194 
195  int fieldIDOffset = offset + numIDs;
196  for(i=0; i<numIDs; ++i) {
197  int thisNumIndices = 0;
198  for(int j=0; j<numFieldsPerID[i]; ++j) {
199  int fieldSize = fieldSizes[totalNumFields_];
200  int fieldID = fieldIDs[totalNumFields_++];
201  if (fieldID != firstFieldID) oneDistinctFieldID = false;
202  data_[fieldIDOffset++] = fieldID;
203  numIndices_ += fieldSize;
204  thisNumIndices += fieldSize;
205  }
206  data_[offset+i] = thisNumIndices;
207  }
208 
209  if (oneDistinctFieldID == true && maxNumFieldsPerID < 2 &&
210  oneDistinctIDType == true) {
212  }
213  else if (oneDistinctIDType == true) {
215  }
216 
217  idTypes_ = &(data_[0]);
221 }
222 
223 //-----------------------------------------------------------------------------
225 {
226 }
227 
228 //-----------------------------------------------------------------------------
230 {
231  return type_ == rhs.type_ &&
232  numIDs_ == rhs.numIDs_ &&
233  totalNumFields_ == rhs.totalNumFields_ &&
234  numIndices_ == rhs.numIndices_ &&
235  data_ == rhs.data_;
236 }
237 
238 //-----------------------------------------------------------------------------
240 {
241  return !(*this == rhs);
242 }
243 
bool operator==(const Pattern &rhs) const
std::vector< int > data_
const int * numFieldsPerID_
const int * idTypes_
const int * fieldIDs_
const int * numIndicesPerID_
PatternType type_
Pattern(int numIDs, int idType, snl_fei::RecordCollection *records)
Definition: fei_Pattern.cpp:12
bool operator!=(const Pattern &rhs) const
virtual ~Pattern()