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 
00057     void setIDType(int idType) { idType_ = idType; }
00058 
00060     bool isPenalty() const { return( isPenalty_ ); }
00061 
00064     void setIsPenalty(bool isPenaltyConstr) { isPenalty_ = isPenaltyConstr; }
00065 
00068     int getEqnNumber() const { return( eqnNumber_ ); }
00069 
00072     void setEqnNumber(int eqn) { eqnNumber_ = eqn; }
00073 
00076     int getBlkEqnNumber() const { return( blkEqnNumber_ ); }
00077 
00080     void setBlkEqnNumber(int blkEqn) { blkEqnNumber_ = blkEqn; }
00081 
00082 
00084     RecordType getSlave() { return( slave_ ); }
00085 
00087     void setSlave(const RecordType& slv) { slave_ = slv; }
00088 
00091     int getSlaveFieldID() const { return( slaveField_ ); }
00092 
00095     void setSlaveFieldID(int f) { slaveField_ = f; }
00096 
00098     int getOffsetIntoSlaveField() const { return( offsetIntoSlaveField_ ); }
00099 
00101     void setOffsetIntoSlaveField(int offset) { offsetIntoSlaveField_ = offset; }
00102 
00103 
00105     std::vector<RecordType>& getMasters() { return( masters_ ); }
00106 
00108     std::vector<int>& getMasterIDTypes() { return( masterIDTypes_ ); }
00109 
00111     std::vector<int>& getMasterFieldIDs() { return( masterFields_ ); }
00112 
00114     std::vector<double>& getMasterWeights() { return( masterWeights_ ); }
00115 
00116 
00118     double getRHSValue() const { return( rhsValue_ ); }
00119 
00121     void setRHSValue(double rhs) { rhsValue_ = rhs; }
00122  
00124     bool operator!=(const Constraint<RecordType>& rhs);
00125 
00127     bool structurallySame(const Constraint<RecordType>& rhs);
00128 
00129   private:
00130     Constraint(const Constraint<RecordType>& src);
00131     Constraint<RecordType>& operator=(const Constraint<RecordType>& src)
00132       {
00133         return(*this);
00134       }
00135 
00136     int constraintID_;
00137     int idType_;
00138     bool isPenalty_;
00139 
00140     int eqnNumber_;
00141     int blkEqnNumber_;
00142 
00143     RecordType slave_;
00144     int slaveField_;
00145     int offsetIntoSlaveField_;
00146 
00147     std::vector<RecordType> masters_;
00148     std::vector<int> masterIDTypes_;
00149     std::vector<int> masterFields_;
00150     std::vector<double> masterWeights_;
00151 
00152     double rhsValue_;
00153 
00154   };//class Constraint
00155 } //namespace snl_fei
00156 
00157 #include <snl_fei_Constraint.hpp>
00158 
00159 //----------------------------------------------------------------------------
00160 template<class RecordType>
00161 inline snl_fei::Constraint<RecordType>::Constraint(int id, bool isPenaltyConstr)
00162   : constraintID_(id),
00163     idType_(0),
00164     isPenalty_(isPenaltyConstr),
00165     eqnNumber_(-1),
00166     blkEqnNumber_(-1),
00167     slave_(),
00168     slaveField_(0),
00169     offsetIntoSlaveField_(0),
00170     masters_(),
00171     masterIDTypes_(),
00172     masterFields_(),
00173     masterWeights_(),
00174     rhsValue_(0.0)
00175 {
00176 }
00177 
00178 //----------------------------------------------------------------------------
00179 template<class RecordType>
00180 inline snl_fei::Constraint<RecordType>::Constraint(int id,
00181                                             int constraintIDType,
00182                                             bool isSlave,
00183                                             bool isPenaltyConstr,
00184                                             int numIDs,
00185                                             const int* idTypes,
00186                                             const int* IDs,
00187                                             const int* fieldIDs,
00188                                             int offsetOfSlave,
00189                                             int offsetIntoSlaveField,
00190                                             const double* weights,
00191                                             double rhsValue,
00192                                             fei::VectorSpace* vspace)
00193   : constraintID_(id),
00194     idType_(constraintIDType),
00195     isPenalty_(isPenaltyConstr),
00196     eqnNumber_(-1),
00197     blkEqnNumber_(-1), 
00198     slave_(),
00199     slaveField_(0),
00200     offsetIntoSlaveField_(offsetIntoSlaveField),
00201     masters_(),
00202     masterIDTypes_(),
00203     masterFields_(),
00204     masterWeights_(),
00205     rhsValue_(rhsValue)
00206 {
00207 }
00208 
00209 //----------------------------------------------------------------------------
00210 namespace snl_fei {
00211 template<>
00212 inline snl_fei::Constraint<fei::Record<int>*>::Constraint(int id,
00213                                             int constraintIDType,
00214                                             bool isSlave,
00215                                             bool isPenaltyConstr,
00216                                             int numIDs,
00217                                             const int* idTypes,
00218                                             const int* IDs,
00219                                             const int* fieldIDs,
00220                                             int offsetOfSlave,
00221                                             int offsetIntoSlaveField,
00222                                             const double* weights,
00223                                             double rhsValue,
00224                                             fei::VectorSpace* vspace)
00225   : constraintID_(id),
00226     idType_(constraintIDType),
00227     isPenalty_(isPenaltyConstr),
00228     eqnNumber_(-1),
00229     blkEqnNumber_(-1), 
00230     slave_(),
00231     slaveField_(0),
00232     offsetIntoSlaveField_(offsetIntoSlaveField),
00233     masters_(),
00234     masterIDTypes_(),
00235     masterFields_(),
00236     masterWeights_(),
00237     rhsValue_(rhsValue)
00238 {
00239   int weightsOffset = 0;
00240   for(int i=0; i<numIDs; ++i) {
00241     snl_fei::RecordCollection* recordCollection = NULL;
00242     vspace->getRecordCollection(idTypes[i],recordCollection);
00243 
00244     vspace->addDOFs(fieldIDs[i], 1, idTypes[i], 1, &(IDs[i]));
00245     fei::Record<int>* rec = recordCollection->getRecordWithID(IDs[i]);
00246 
00247     unsigned fieldSize = vspace->getFieldSize(fieldIDs[i]);
00248 
00249     if (isSlave && i == offsetOfSlave) {
00250       rec->hasSlaveDof(true);
00251       setSlave(rec);
00252       setSlaveFieldID(fieldIDs[i]);
00253       setOffsetIntoSlaveField(offsetIntoSlaveField);
00254       weightsOffset += fieldSize;
00255     }
00256     else {
00257       getMasters().push_back(rec);
00258       getMasterIDTypes().push_back(idTypes[i]);
00259       getMasterFieldIDs().push_back(fieldIDs[i]);
00260 
00261       if (weights != NULL) {
00262         for(unsigned j=0; j<fieldSize; ++j) {
00263           masterWeights_.push_back(weights[weightsOffset++]);
00264         }
00265       }
00266     }
00267   }
00268 }
00269 
00270 }//namespace snl_fei
00271 
00272 //----------------------------------------------------------------------------
00273 template<class RecordType>
00274 inline snl_fei::Constraint<RecordType>::Constraint(const Constraint<RecordType>& src)
00275   : constraintID_(-1),
00276     idType_(0),
00277     isPenalty_(false),
00278     eqnNumber_(-1),
00279     blkEqnNumber_(-1), 
00280     slave_(),
00281     slaveField_(0),
00282     offsetIntoSlaveField_(0),
00283     masters_(),
00284     masterIDTypes_(),
00285     masterFields_(),
00286     masterWeights_(),
00287     rhsValue_(0.0)
00288 {
00289 }
00290 
00291 //----------------------------------------------------------------------------
00292 template<class RecordType>
00293 inline snl_fei::Constraint<RecordType>::~Constraint()
00294 {
00295 }
00296 
00297 //----------------------------------------------------------------------------
00298 template<class RecordType>
00299 inline bool snl_fei::Constraint<RecordType>::operator!=(const snl_fei::Constraint<RecordType>& rhs)
00300 {
00301   if (constraintID_ != rhs.constraintID_ ||
00302       idType_ != rhs.idType_ ||
00303       isPenalty_ != rhs.isPenalty_ ||
00304       eqnNumber_ != rhs.eqnNumber_ ||
00305       blkEqnNumber_ != rhs.blkEqnNumber_ ||
00306       slaveField_ != rhs.slaveField_ ||
00307       offsetIntoSlaveField_ != rhs.offsetIntoSlaveField_ ||
00308       rhsValue_ != rhs.rhsValue_) {
00309     return( true );
00310   }
00311 
00312   if (masters_ != rhs.masters_) return(true);
00313 
00314   if (masterIDTypes_ != rhs.masterIDTypes_) return(true);
00315 
00316   if (masterFields_ != rhs.masterFields_) return(true);
00317 
00318   if (masterWeights_ != rhs.masterWeights_) return(true);
00319 
00320   return(false);
00321 }
00322 
00323 //----------------------------------------------------------------------------
00324 template<class RecordType>
00325 inline bool snl_fei::Constraint<RecordType>::structurallySame(const Constraint<RecordType>& rhs)
00326 {
00327   if (constraintID_ != rhs.constraintID_ ||
00328       idType_ != rhs.idType_ ||
00329       isPenalty_ != rhs.isPenalty_ ||
00330       eqnNumber_ != rhs.eqnNumber_ ||
00331       blkEqnNumber_ != rhs.blkEqnNumber_ ||
00332       slaveField_ != rhs.slaveField_ ||
00333       offsetIntoSlaveField_ != rhs.offsetIntoSlaveField_) {
00334     return( false );
00335   }
00336 
00337   if (masters_ != rhs.masters_) return(false);
00338 
00339   if (masterIDTypes_ != rhs.masterIDTypes_) return(false);
00340 
00341   if (masterFields_ != rhs.masterFields_) return(false);
00342 
00343   return(true);
00344 }
00345 
00346 #endif // _snl_fei_Constraint_hpp_
00347 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends
Generated on Wed Apr 13 10:08:24 2011 for FEI by  doxygen 1.6.3