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 getRecordCollection()->getRecordWithLocalID(slave_); }
00087 
00089     void setSlave(int 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     int constraintID_;
00139     int idType_;
00140     snl_fei::RecordCollection* recordCollection_;
00141     bool isPenalty_;
00142 
00143     int eqnNumber_;
00144     int blkEqnNumber_;
00145 
00146     int slave_;
00147     int slaveField_;
00148     int offsetIntoSlaveField_;
00149 
00150     std::vector<int> masters_;
00151     std::vector<int> masterIDTypes_;
00152     std::vector<snl_fei::RecordCollection*> masterRecordCollections_;
00153     std::vector<int> masterFields_;
00154     std::vector<double> masterWeights_;
00155 
00156     double rhsValue_;
00157 
00158   };//class Constraint
00159 } //namespace snl_fei
00160 
00161 #include <snl_fei_Constraint.hpp>
00162 
00163 //----------------------------------------------------------------------------
00164 template<class RecordType>
00165 inline snl_fei::Constraint<RecordType>::Constraint(int id, bool isPenaltyConstr)
00166   : constraintID_(id),
00167     idType_(0),
00168     recordCollection_(NULL),
00169     isPenalty_(isPenaltyConstr),
00170     eqnNumber_(-1),
00171     blkEqnNumber_(-1),
00172     slave_(),
00173     slaveField_(0),
00174     offsetIntoSlaveField_(0),
00175     masters_(),
00176     masterIDTypes_(),
00177     masterRecordCollections_(),
00178     masterFields_(),
00179     masterWeights_(),
00180     rhsValue_(0.0)
00181 {
00182 }
00183 
00184 //----------------------------------------------------------------------------
00185 template<class RecordType>
00186 inline snl_fei::Constraint<RecordType>::Constraint(int id,
00187                                             int constraintIDType,
00188                                             bool isSlave,
00189                                             bool isPenaltyConstr,
00190                                             int numIDs,
00191                                             const int* idTypes,
00192                                             const int* IDs,
00193                                             const int* fieldIDs,
00194                                             int offsetOfSlave,
00195                                             int offsetIntoSlaveField,
00196                                             const double* weights,
00197                                             double rhsValue,
00198                                             fei::VectorSpace* vspace)
00199   : constraintID_(id),
00200     idType_(constraintIDType),
00201     recordCollection_(NULL),
00202     isPenalty_(isPenaltyConstr),
00203     eqnNumber_(-1),
00204     blkEqnNumber_(-1), 
00205     slave_(),
00206     slaveField_(0),
00207     offsetIntoSlaveField_(offsetIntoSlaveField),
00208     masters_(),
00209     masterIDTypes_(),
00210     masterRecordCollections_(),
00211     masterFields_(),
00212     masterWeights_(),
00213     rhsValue_(rhsValue)
00214 {
00215 }
00216 
00217 //----------------------------------------------------------------------------
00218 namespace snl_fei {
00219 template<>
00220 inline snl_fei::Constraint<fei::Record<int>*>::Constraint(int id,
00221                                             int constraintIDType,
00222                                             bool isSlave,
00223                                             bool isPenaltyConstr,
00224                                             int numIDs,
00225                                             const int* idTypes,
00226                                             const int* IDs,
00227                                             const int* fieldIDs,
00228                                             int offsetOfSlave,
00229                                             int offsetIntoSlaveField,
00230                                             const double* weights,
00231                                             double rhsValue,
00232                                             fei::VectorSpace* vspace)
00233   : constraintID_(id),
00234     idType_(constraintIDType),
00235     recordCollection_(NULL),
00236     isPenalty_(isPenaltyConstr),
00237     eqnNumber_(-1),
00238     blkEqnNumber_(-1), 
00239     slave_(),
00240     slaveField_(0),
00241     offsetIntoSlaveField_(offsetIntoSlaveField),
00242     masters_(),
00243     masterIDTypes_(),
00244     masterRecordCollections_(),
00245     masterFields_(),
00246     masterWeights_(),
00247     rhsValue_(rhsValue)
00248 {
00249   int weightsOffset = 0;
00250   snl_fei::RecordCollection* recordCollection = NULL;
00251   vspace->getRecordCollection(idType_, recordCollection);
00252   recordCollection_ = recordCollection;
00253   for(int i=0; i<numIDs; ++i) {
00254     vspace->getRecordCollection(idTypes[i],recordCollection);
00255     masterRecordCollections_.push_back(recordCollection);
00256 
00257     vspace->addDOFs(fieldIDs[i], idTypes[i], 1, &(IDs[i]));
00258     int rec_local_id = recordCollection->getLocalID(IDs[i]);
00259     fei::Record<int>* rec = recordCollection->getRecordWithLocalID(rec_local_id);
00260     
00261     unsigned fieldSize = vspace->getFieldSize(fieldIDs[i]);
00262 
00263     if (isSlave && i == offsetOfSlave) {
00264       rec->hasSlaveDof(true);
00265       setSlave(rec_local_id);
00266       setSlaveFieldID(fieldIDs[i]);
00267       setOffsetIntoSlaveField(offsetIntoSlaveField);
00268       weightsOffset += fieldSize;
00269     }
00270     else {
00271       getMasters().push_back(rec_local_id);
00272       getMasterIDTypes().push_back(idTypes[i]);
00273       getMasterFieldIDs().push_back(fieldIDs[i]);
00274 
00275       if (weights != NULL) {
00276         for(unsigned j=0; j<fieldSize; ++j) {
00277           masterWeights_.push_back(weights[weightsOffset++]);
00278         }
00279       }
00280     }
00281   }
00282 }
00283 
00284 }//namespace snl_fei
00285 
00286 //----------------------------------------------------------------------------
00287 template<class RecordType>
00288 inline snl_fei::Constraint<RecordType>::Constraint(const Constraint<RecordType>& src)
00289   : constraintID_(-1),
00290     idType_(0),
00291     isPenalty_(false),
00292     eqnNumber_(-1),
00293     blkEqnNumber_(-1), 
00294     slave_(),
00295     slaveField_(0),
00296     offsetIntoSlaveField_(0),
00297     masters_(),
00298     masterIDTypes_(),
00299     masterRecordCollections_(),
00300     masterFields_(),
00301     masterWeights_(),
00302     rhsValue_(0.0)
00303 {
00304 }
00305 
00306 //----------------------------------------------------------------------------
00307 template<class RecordType>
00308 inline snl_fei::Constraint<RecordType>::~Constraint()
00309 {
00310 }
00311 
00312 //----------------------------------------------------------------------------
00313 template<class RecordType>
00314 inline bool snl_fei::Constraint<RecordType>::operator!=(const snl_fei::Constraint<RecordType>& rhs)
00315 {
00316   if (constraintID_ != rhs.constraintID_ ||
00317       idType_ != rhs.idType_ ||
00318       isPenalty_ != rhs.isPenalty_ ||
00319       eqnNumber_ != rhs.eqnNumber_ ||
00320       blkEqnNumber_ != rhs.blkEqnNumber_ ||
00321       slaveField_ != rhs.slaveField_ ||
00322       offsetIntoSlaveField_ != rhs.offsetIntoSlaveField_ ||
00323       rhsValue_ != rhs.rhsValue_) {
00324     return( true );
00325   }
00326 
00327   if (masters_ != rhs.masters_) return(true);
00328 
00329   if (masterIDTypes_ != rhs.masterIDTypes_) return(true);
00330 
00331   if (masterFields_ != rhs.masterFields_) return(true);
00332 
00333   if (masterWeights_ != rhs.masterWeights_) return(true);
00334 
00335   return(false);
00336 }
00337 
00338 //----------------------------------------------------------------------------
00339 template<class RecordType>
00340 inline bool snl_fei::Constraint<RecordType>::structurallySame(const Constraint<RecordType>& rhs)
00341 {
00342   if (constraintID_ != rhs.constraintID_ ||
00343       idType_ != rhs.idType_ ||
00344       isPenalty_ != rhs.isPenalty_ ||
00345       eqnNumber_ != rhs.eqnNumber_ ||
00346       blkEqnNumber_ != rhs.blkEqnNumber_ ||
00347       slaveField_ != rhs.slaveField_ ||
00348       offsetIntoSlaveField_ != rhs.offsetIntoSlaveField_) {
00349     return( false );
00350   }
00351 
00352   if (masters_ != rhs.masters_) return(false);
00353 
00354   if (masterIDTypes_ != rhs.masterIDTypes_) return(false);
00355 
00356   if (masterFields_ != rhs.masterFields_) return(false);
00357 
00358   return(true);
00359 }
00360 
00361 #endif // _snl_fei_Constraint_hpp_
00362 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends