FEI Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
snl_fei_Constraint.hpp
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#ifndef _snl_fei_Constraint_hpp_
10#define _snl_fei_Constraint_hpp_
11
12#include <fei_macros.hpp>
13#include <fei_fwd.hpp>
14#include <fei_VectorSpace.hpp>
16
17#include <vector>
18
19namespace snl_fei {
20
22 template<class RecordType>
23 class Constraint {
24 public:
26 Constraint(int id=0, bool isPenaltyConstr=false);
27
29 Constraint(int id,
30 int constraintIDType,
31 bool isSlave,
32 bool isPenaltyConstr,
33 int numIDs,
34 const int* idTypes,
35 const int* IDs,
36 const int* fieldIDs,
37 int offsetOfSlave,
38 int offsetIntoSlaveField,
39 const double* weights,
40 double rhsValue,
41 fei::VectorSpace* vspace);
42
44 virtual ~Constraint();
45
47 int getConstraintID() const { return( constraintID_ ); }
48
50 void setConstraintID(int id) { constraintID_ = id; }
51
53 int getIDType() const { return( idType_ ); }
54
56
59 void setIDType(int idType) { idType_ = idType; }
60
62 bool isPenalty() const { return( isPenalty_ ); }
63
66 void setIsPenalty(bool isPenaltyConstr) { isPenalty_ = isPenaltyConstr; }
67
70 int getEqnNumber() const { return( eqnNumber_ ); }
71
74 void setEqnNumber(int eqn) { eqnNumber_ = eqn; }
75
78 int getBlkEqnNumber() const { return( blkEqnNumber_ ); }
79
82 void setBlkEqnNumber(int blkEqn) { blkEqnNumber_ = blkEqn; }
83
84
87
89 void setSlave(int slv) { slave_ = slv; }
90
93 int getSlaveFieldID() const { return( slaveField_ ); }
94
97 void setSlaveFieldID(int f) { slaveField_ = f; }
98
101
103 void setOffsetIntoSlaveField(int offset) { offsetIntoSlaveField_ = offset; }
104
105
107 std::vector<int>& getMasters() { return( masters_ ); }
108
110 std::vector<int>& getMasterIDTypes() { return( masterIDTypes_ ); }
111
113 std::vector<snl_fei::RecordCollection*>& getMasterRecordCollections() { return masterRecordCollections_; }
114
116 std::vector<int>& getMasterFieldIDs() { return( masterFields_ ); }
117
119 std::vector<double>& getMasterWeights() { return( masterWeights_ ); }
120
121
123 double getRHSValue() const { return( rhsValue_ ); }
124
126 void setRHSValue(double rhs) { rhsValue_ = rhs; }
127
129 bool operator!=(const Constraint<RecordType>& rhs);
130
133
134 private:
137
142
145
149
150 std::vector<int> masters_;
151 std::vector<int> masterIDTypes_;
152 std::vector<snl_fei::RecordCollection*> masterRecordCollections_;
153 std::vector<int> masterFields_;
154 std::vector<double> masterWeights_;
155
156 double rhsValue_;
157
158 };//class Constraint
159} //namespace snl_fei
160
161#include <snl_fei_Constraint.hpp>
162
163//----------------------------------------------------------------------------
164template<class RecordType>
165inline snl_fei::Constraint<RecordType>::Constraint(int id, bool isPenaltyConstr)
166 : constraintID_(id),
167 idType_(0),
168 recordCollection_(NULL),
169 isPenalty_(isPenaltyConstr),
170 eqnNumber_(-1),
171 blkEqnNumber_(-1),
172 slave_(),
173 slaveField_(0),
174 offsetIntoSlaveField_(0),
175 masters_(),
176 masterIDTypes_(),
177 masterRecordCollections_(),
178 masterFields_(),
179 masterWeights_(),
180 rhsValue_(0.0)
181{
182}
183
184//----------------------------------------------------------------------------
185template<class RecordType>
187 int constraintIDType,
188 bool isSlave,
189 bool isPenaltyConstr,
190 int numIDs,
191 const int* idTypes,
192 const int* IDs,
193 const int* fieldIDs,
194 int offsetOfSlave,
195 int offsetIntoSlaveField,
196 const double* weights,
197 double rhsValue,
198 fei::VectorSpace* vspace)
199 : constraintID_(id),
200 idType_(constraintIDType),
201 recordCollection_(NULL),
202 isPenalty_(isPenaltyConstr),
203 eqnNumber_(-1),
204 blkEqnNumber_(-1),
205 slave_(),
206 slaveField_(0),
207 offsetIntoSlaveField_(offsetIntoSlaveField),
208 masters_(),
209 masterIDTypes_(),
210 masterRecordCollections_(),
211 masterFields_(),
212 masterWeights_(),
213 rhsValue_(rhsValue)
214{
215}
216
217//----------------------------------------------------------------------------
218namespace snl_fei {
219template<>
220inline snl_fei::Constraint<fei::Record<int>*>::Constraint(int id,
221 int constraintIDType,
222 bool isSlave,
223 bool isPenaltyConstr,
224 int numIDs,
225 const int* idTypes,
226 const int* IDs,
227 const int* fieldIDs,
228 int offsetOfSlave,
229 int offsetIntoSlaveField,
230 const double* weights,
231 double rhsValue,
232 fei::VectorSpace* vspace)
233 : constraintID_(id),
234 idType_(constraintIDType),
235 recordCollection_(NULL),
236 isPenalty_(isPenaltyConstr),
237 eqnNumber_(-1),
238 blkEqnNumber_(-1),
239 slave_(),
240 slaveField_(0),
241 offsetIntoSlaveField_(offsetIntoSlaveField),
242 masters_(),
243 masterIDTypes_(),
244 masterRecordCollections_(),
245 masterFields_(),
246 masterWeights_(),
247 rhsValue_(rhsValue)
248{
249 int weightsOffset = 0;
250 snl_fei::RecordCollection* recordCollection = NULL;
251 vspace->getRecordCollection(idType_, recordCollection);
252 recordCollection_ = recordCollection;
253 for(int i=0; i<numIDs; ++i) {
254 vspace->getRecordCollection(idTypes[i],recordCollection);
255 masterRecordCollections_.push_back(recordCollection);
256
257 vspace->addDOFs(fieldIDs[i], idTypes[i], 1, &(IDs[i]));
258 int rec_local_id = recordCollection->getLocalID(IDs[i]);
259 fei::Record<int>* rec = recordCollection->getRecordWithLocalID(rec_local_id);
260
261 unsigned fieldSize = vspace->getFieldSize(fieldIDs[i]);
262
263 if (isSlave && i == offsetOfSlave) {
264 rec->hasSlaveDof(true);
265 setSlave(rec_local_id);
266 setSlaveFieldID(fieldIDs[i]);
267 setOffsetIntoSlaveField(offsetIntoSlaveField);
268 weightsOffset += fieldSize;
269 }
270 else {
271 getMasters().push_back(rec_local_id);
272 getMasterIDTypes().push_back(idTypes[i]);
273 getMasterFieldIDs().push_back(fieldIDs[i]);
274
275 if (weights != NULL) {
276 for(unsigned j=0; j<fieldSize; ++j) {
277 masterWeights_.push_back(weights[weightsOffset++]);
278 }
279 }
280 }
281 }
282}
283
284}//namespace snl_fei
285
286//----------------------------------------------------------------------------
287template<class RecordType>
289 : constraintID_(-1),
290 idType_(0),
291 isPenalty_(false),
292 eqnNumber_(-1),
293 blkEqnNumber_(-1),
294 slave_(),
295 slaveField_(0),
296 offsetIntoSlaveField_(0),
297 masters_(),
298 masterIDTypes_(),
299 masterRecordCollections_(),
300 masterFields_(),
301 masterWeights_(),
302 rhsValue_(0.0)
303{
304}
305
306//----------------------------------------------------------------------------
307template<class RecordType>
311
312//----------------------------------------------------------------------------
313template<class RecordType>
315{
316 if (constraintID_ != rhs.constraintID_ ||
317 idType_ != rhs.idType_ ||
318 isPenalty_ != rhs.isPenalty_ ||
319 eqnNumber_ != rhs.eqnNumber_ ||
320 blkEqnNumber_ != rhs.blkEqnNumber_ ||
321 slaveField_ != rhs.slaveField_ ||
322 offsetIntoSlaveField_ != rhs.offsetIntoSlaveField_ ||
323 rhsValue_ != rhs.rhsValue_) {
324 return( true );
325 }
326
327 if (masters_ != rhs.masters_) return(true);
328
329 if (masterIDTypes_ != rhs.masterIDTypes_) return(true);
330
331 if (masterFields_ != rhs.masterFields_) return(true);
332
333 if (masterWeights_ != rhs.masterWeights_) return(true);
334
335 return(false);
336}
337
338//----------------------------------------------------------------------------
339template<class RecordType>
341{
342 if (constraintID_ != rhs.constraintID_ ||
343 idType_ != rhs.idType_ ||
344 isPenalty_ != rhs.isPenalty_ ||
345 eqnNumber_ != rhs.eqnNumber_ ||
346 blkEqnNumber_ != rhs.blkEqnNumber_ ||
347 slaveField_ != rhs.slaveField_ ||
348 offsetIntoSlaveField_ != rhs.offsetIntoSlaveField_) {
349 return( false );
350 }
351
352 if (masters_ != rhs.masters_) return(false);
353
354 if (masterIDTypes_ != rhs.masterIDTypes_) return(false);
355
356 if (masterFields_ != rhs.masterFields_) return(false);
357
358 return(true);
359}
360
361#endif // _snl_fei_Constraint_hpp_
362
bool hasSlaveDof() const
unsigned getFieldSize(int fieldID)
int addDOFs(int fieldID, int idType, int numIDs, const int *IDs)
int getRecordCollection(int idType, snl_fei::RecordCollection *&records)
std::vector< int > & getMasterIDTypes()
std::vector< int > & getMasterFieldIDs()
std::vector< int > masterFields_
void setIDType(int idType)
bool structurallySame(const Constraint< RecordType > &rhs)
std::vector< snl_fei::RecordCollection * > masterRecordCollections_
std::vector< snl_fei::RecordCollection * > & getMasterRecordCollections()
bool operator!=(const Constraint< RecordType > &rhs)
void setBlkEqnNumber(int blkEqn)
void setOffsetIntoSlaveField(int offset)
Constraint(int id=0, bool isPenaltyConstr=false)
std::vector< int > & getMasters()
snl_fei::RecordCollection * recordCollection_
std::vector< double > masterWeights_
void setRHSValue(double rhs)
snl_fei::RecordCollection * getRecordCollection()
std::vector< int > masterIDTypes_
void setIsPenalty(bool isPenaltyConstr)
std::vector< int > masters_
std::vector< double > & getMasterWeights()
Constraint< RecordType > & operator=(const Constraint< RecordType > &src)
int getLocalID(int global_id) const
fei::Record< int > * getRecordWithLocalID(int lid)