FEI Version of the Day
snl_fei_Constraint.hpp
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 #ifndef _snl_fei_Constraint_hpp_
00010 #define _snl_fei_Constraint_hpp_
00011 
00012 #include <fei_macros.hpp>
00013 #include <fei_fwd.hpp>
00014 #include <fei_VectorSpace.hpp>
00015 #include <snl_fei_RecordCollection.hpp>
00016 
00017 #include <vector>
00018 
00019 namespace snl_fei {
00020 
00022   template<class RecordType>
00023   class Constraint {
00024   public:
00026     Constraint(int id=0, bool isPenaltyConstr=false);
00027 
00029     Constraint(int id,
00030                int constraintIDType,
00031                bool isSlave,
00032                bool isPenaltyConstr,
00033                int numIDs,
00034                const int* idTypes,
00035                const int* IDs,
00036                const int* fieldIDs,
00037                int offsetOfSlave,
00038                int offsetIntoSlaveField,
00039                const double* weights,
00040                double rhsValue,
00041                fei::VectorSpace* vspace);
00042 
00044     virtual ~Constraint();
00045 
00047     int getConstraintID() const { return( constraintID_ ); }
00048 
00050     void setConstraintID(int id) { constraintID_ = id; }
00051 
00053     int getIDType() const { return( idType_ ); }
00054 
00055     snl_fei::RecordCollection* getRecordCollection() { return recordCollection_; }
00056 
00059     void setIDType(int idType) { idType_ = idType; }
00060 
00062     bool isPenalty() const { return( isPenalty_ ); }
00063 
00066     void setIsPenalty(bool isPenaltyConstr) { isPenalty_ = isPenaltyConstr; }
00067 
00070     int getEqnNumber() const { return( eqnNumber_ ); }
00071 
00074     void setEqnNumber(int eqn) { eqnNumber_ = eqn; }
00075 
00078     int getBlkEqnNumber() const { return( blkEqnNumber_ ); }
00079 
00082     void setBlkEqnNumber(int blkEqn) { blkEqnNumber_ = blkEqn; }
00083 
00084 
00086     RecordType getSlave() { return( slave_ ); }
00087 
00089     void setSlave(const RecordType& slv) { slave_ = slv; }
00090 
00093     int getSlaveFieldID() const { return( slaveField_ ); }
00094 
00097     void setSlaveFieldID(int f) { slaveField_ = f; }
00098 
00100     int getOffsetIntoSlaveField() const { return( offsetIntoSlaveField_ ); }
00101 
00103     void setOffsetIntoSlaveField(int offset) { offsetIntoSlaveField_ = offset; }
00104 
00105 
00107     std::vector<int>& getMasters() { return( masters_ ); }
00108 
00110     std::vector<int>& getMasterIDTypes() { return( masterIDTypes_ ); }
00111 
00113     std::vector<snl_fei::RecordCollection*>& getMasterRecordCollections() { return masterRecordCollections_; }
00114 
00116     std::vector<int>& getMasterFieldIDs() { return( masterFields_ ); }
00117 
00119     std::vector<double>& getMasterWeights() { return( masterWeights_ ); }
00120 
00121 
00123     double getRHSValue() const { return( rhsValue_ ); }
00124 
00126     void setRHSValue(double rhs) { rhsValue_ = rhs; }
00127  
00129     bool operator!=(const Constraint<RecordType>& rhs);
00130 
00132     bool structurallySame(const Constraint<RecordType>& rhs);
00133 
00134   private:
00135     Constraint(const Constraint<RecordType>& src);
00136     Constraint<RecordType>& operator=(const Constraint<RecordType>& src)
00137       {
00138         return(*this);
00139       }
00140 
00141     int constraintID_;
00142     int idType_;
00143     snl_fei::RecordCollection* recordCollection_;
00144     bool isPenalty_;
00145 
00146     int eqnNumber_;
00147     int blkEqnNumber_;
00148 
00149     RecordType slave_;
00150     int slaveField_;
00151     int offsetIntoSlaveField_;
00152 
00153     std::vector<int> masters_;
00154     std::vector<int> masterIDTypes_;
00155     std::vector<snl_fei::RecordCollection*> masterRecordCollections_;
00156     std::vector<int> masterFields_;
00157     std::vector<double> masterWeights_;
00158 
00159     double rhsValue_;
00160 
00161   };//class Constraint
00162 } //namespace snl_fei
00163 
00164 #include <snl_fei_Constraint.hpp>
00165 
00166 //----------------------------------------------------------------------------
00167 template<class RecordType>
00168 inline snl_fei::Constraint<RecordType>::Constraint(int id, bool isPenaltyConstr)
00169   : constraintID_(id),
00170     idType_(0),
00171     recordCollection_(NULL),
00172     isPenalty_(isPenaltyConstr),
00173     eqnNumber_(-1),
00174     blkEqnNumber_(-1),
00175     slave_(),
00176     slaveField_(0),
00177     offsetIntoSlaveField_(0),
00178     masters_(),
00179     masterIDTypes_(),
00180     masterRecordCollections_(),
00181     masterFields_(),
00182     masterWeights_(),
00183     rhsValue_(0.0)
00184 {
00185 }
00186 
00187 //----------------------------------------------------------------------------
00188 template<class RecordType>
00189 inline snl_fei::Constraint<RecordType>::Constraint(int id,
00190                                             int constraintIDType,
00191                                             bool isSlave,
00192                                             bool isPenaltyConstr,
00193                                             int numIDs,
00194                                             const int* idTypes,
00195                                             const int* IDs,
00196                                             const int* fieldIDs,
00197                                             int offsetOfSlave,
00198                                             int offsetIntoSlaveField,
00199                                             const double* weights,
00200                                             double rhsValue,
00201                                             fei::VectorSpace* vspace)
00202   : constraintID_(id),
00203     idType_(constraintIDType),
00204     recordCollection_(NULL),
00205     isPenalty_(isPenaltyConstr),
00206     eqnNumber_(-1),
00207     blkEqnNumber_(-1), 
00208     slave_(),
00209     slaveField_(0),
00210     offsetIntoSlaveField_(offsetIntoSlaveField),
00211     masters_(),
00212     masterIDTypes_(),
00213     masterRecordCollections_(),
00214     masterFields_(),
00215     masterWeights_(),
00216     rhsValue_(rhsValue)
00217 {
00218 }
00219 
00220 //----------------------------------------------------------------------------
00221 namespace snl_fei {
00222 template<>
00223 inline snl_fei::Constraint<fei::Record<int>*>::Constraint(int id,
00224                                             int constraintIDType,
00225                                             bool isSlave,
00226                                             bool isPenaltyConstr,
00227                                             int numIDs,
00228                                             const int* idTypes,
00229                                             const int* IDs,
00230                                             const int* fieldIDs,
00231                                             int offsetOfSlave,
00232                                             int offsetIntoSlaveField,
00233                                             const double* weights,
00234                                             double rhsValue,
00235                                             fei::VectorSpace* vspace)
00236   : constraintID_(id),
00237     idType_(constraintIDType),
00238     recordCollection_(NULL),
00239     isPenalty_(isPenaltyConstr),
00240     eqnNumber_(-1),
00241     blkEqnNumber_(-1), 
00242     slave_(),
00243     slaveField_(0),
00244     offsetIntoSlaveField_(offsetIntoSlaveField),
00245     masters_(),
00246     masterIDTypes_(),
00247     masterRecordCollections_(),
00248     masterFields_(),
00249     masterWeights_(),
00250     rhsValue_(rhsValue)
00251 {
00252   int weightsOffset = 0;
00253   snl_fei::RecordCollection* recordCollection = NULL;
00254   vspace->getRecordCollection(idType_, recordCollection);
00255   recordCollection_ = recordCollection;
00256   for(int i=0; i<numIDs; ++i) {
00257     vspace->getRecordCollection(idTypes[i],recordCollection);
00258     masterRecordCollections_.push_back(recordCollection);
00259 
00260     vspace->addDOFs(fieldIDs[i], idTypes[i], 1, &(IDs[i]));
00261     int rec_local_id = recordCollection->getLocalID(IDs[i]);
00262     fei::Record<int>* rec = recordCollection->getRecordWithLocalID(rec_local_id);
00263     
00264     unsigned fieldSize = vspace->getFieldSize(fieldIDs[i]);
00265 
00266     if (isSlave && i == offsetOfSlave) {
00267       rec->hasSlaveDof(true);
00268       setSlave(rec);
00269       setSlaveFieldID(fieldIDs[i]);
00270       setOffsetIntoSlaveField(offsetIntoSlaveField);
00271       weightsOffset += fieldSize;
00272     }
00273     else {
00274       getMasters().push_back(rec_local_id);
00275       getMasterIDTypes().push_back(idTypes[i]);
00276       getMasterFieldIDs().push_back(fieldIDs[i]);
00277 
00278       if (weights != NULL) {
00279         for(unsigned j=0; j<fieldSize; ++j) {
00280           masterWeights_.push_back(weights[weightsOffset++]);
00281         }
00282       }
00283     }
00284   }
00285 }
00286 
00287 }//namespace snl_fei
00288 
00289 //----------------------------------------------------------------------------
00290 template<class RecordType>
00291 inline snl_fei::Constraint<RecordType>::Constraint(const Constraint<RecordType>& src)
00292   : constraintID_(-1),
00293     idType_(0),
00294     isPenalty_(false),
00295     eqnNumber_(-1),
00296     blkEqnNumber_(-1), 
00297     slave_(),
00298     slaveField_(0),
00299     offsetIntoSlaveField_(0),
00300     masters_(),
00301     masterIDTypes_(),
00302     masterRecordCollections_(),
00303     masterFields_(),
00304     masterWeights_(),
00305     rhsValue_(0.0)
00306 {
00307 }
00308 
00309 //----------------------------------------------------------------------------
00310 template<class RecordType>
00311 inline snl_fei::Constraint<RecordType>::~Constraint()
00312 {
00313 }
00314 
00315 //----------------------------------------------------------------------------
00316 template<class RecordType>
00317 inline bool snl_fei::Constraint<RecordType>::operator!=(const snl_fei::Constraint<RecordType>& rhs)
00318 {
00319   if (constraintID_ != rhs.constraintID_ ||
00320       idType_ != rhs.idType_ ||
00321       isPenalty_ != rhs.isPenalty_ ||
00322       eqnNumber_ != rhs.eqnNumber_ ||
00323       blkEqnNumber_ != rhs.blkEqnNumber_ ||
00324       slaveField_ != rhs.slaveField_ ||
00325       offsetIntoSlaveField_ != rhs.offsetIntoSlaveField_ ||
00326       rhsValue_ != rhs.rhsValue_) {
00327     return( true );
00328   }
00329 
00330   if (masters_ != rhs.masters_) return(true);
00331 
00332   if (masterIDTypes_ != rhs.masterIDTypes_) return(true);
00333 
00334   if (masterFields_ != rhs.masterFields_) return(true);
00335 
00336   if (masterWeights_ != rhs.masterWeights_) return(true);
00337 
00338   return(false);
00339 }
00340 
00341 //----------------------------------------------------------------------------
00342 template<class RecordType>
00343 inline bool snl_fei::Constraint<RecordType>::structurallySame(const Constraint<RecordType>& rhs)
00344 {
00345   if (constraintID_ != rhs.constraintID_ ||
00346       idType_ != rhs.idType_ ||
00347       isPenalty_ != rhs.isPenalty_ ||
00348       eqnNumber_ != rhs.eqnNumber_ ||
00349       blkEqnNumber_ != rhs.blkEqnNumber_ ||
00350       slaveField_ != rhs.slaveField_ ||
00351       offsetIntoSlaveField_ != rhs.offsetIntoSlaveField_) {
00352     return( false );
00353   }
00354 
00355   if (masters_ != rhs.masters_) return(false);
00356 
00357   if (masterIDTypes_ != rhs.masterIDTypes_) return(false);
00358 
00359   if (masterFields_ != rhs.masterFields_) return(false);
00360 
00361   return(true);
00362 }
00363 
00364 #endif // _snl_fei_Constraint_hpp_
00365 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends