MP_Constraint.cpp

Go to the documentation of this file.
00001 /* ****************************************************************** **
00002 **    OpenSees - Open System for Earthquake Engineering Simulation    **
00003 **          Pacific Earthquake Engineering Research Center            **
00004 **                                                                    **
00005 **                                                                    **
00006 ** (C) Copyright 1999, The Regents of the University of California    **
00007 ** All Rights Reserved.                                               **
00008 **                                                                    **
00009 ** Commercial use of this program without express permission of the   **
00010 ** University of California, Berkeley, is strictly prohibited.  See   **
00011 ** file 'COPYRIGHT'  in main directory for information on usage and   **
00012 ** redistribution,  and for a DISCLAIMER OF ALL WARRANTIES.           **
00013 **                                                                    **
00014 ** Developed by:                                                      **
00015 **   Frank McKenna (fmckenna@ce.berkeley.edu)                         **
00016 **   Gregory L. Fenves (fenves@ce.berkeley.edu)                       **
00017 **   Filip C. Filippou (filippou@ce.berkeley.edu)                     **
00018 **                                                                    **
00019 ** ****************************************************************** */
00020                                                                         
00021 // $Revision: 1.4 $
00022 // $Date: 2005/12/22 00:35:08 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/domain/constraints/MP_Constraint.cpp,v $
00024                                                                         
00025                                                                         
00026 // File: ~/domain/constraints//MP_Constraint.C
00027 //
00028 // Written: fmk 
00029 // Created: 11/96
00030 // Revision: A
00031 //
00032 // Purpose: This file contains the implementation of class MP_Constraint.
00033 //
00034 // The class MP_Constraint interface:
00035 //
00036 
00037 #include <MP_Constraint.h>
00038 
00039 #include <stdlib.h>
00040 #include <Matrix.h>
00041 #include <ID.h>
00042 #include <Channel.h>
00043 #include <FEM_ObjectBroker.h>
00044  
00045 // constructor for FEM_ObjectBroker                     // Arash
00046 MP_Constraint::MP_Constraint( int tag , int clasTag )           
00047 :DomainComponent(tag,clasTag),
00048  nodeRetained(0),nodeConstrained(0),constraint(0),constrDOF(0),retainDOF(0),
00049  dbTag1(0), dbTag2(0)
00050 {
00051     
00052 }
00053 
00054 // constructor for Subclass
00055 MP_Constraint::MP_Constraint(int tag, int nodeRetain, int nodeConstr, 
00056                              ID &constrainedDOF, 
00057                              ID &retainedDOF, int clasTag)
00058 :DomainComponent(tag, clasTag),
00059  nodeRetained(nodeRetain), nodeConstrained(nodeConstr), 
00060  constraint(0), constrDOF(0), retainDOF(0),  dbTag1(0), dbTag2(0)
00061 {
00062     constrDOF = new ID(constrainedDOF);
00063     retainDOF = new ID(retainedDOF);    
00064     if (constrDOF == 0 || constrainedDOF.Size() != constrDOF->Size() ||
00065         retainDOF == 0 || retainedDOF.Size() != retainDOF->Size()) { 
00066         opserr << "MP_Constraint::MP_Constraint - ran out of memory 1\n";
00067         exit(-1);
00068     }    
00069 }
00070 
00071 
00072 // general constructor for ModelBuilder
00073 MP_Constraint::MP_Constraint(int tag, int nodeRetain, int nodeConstr, Matrix &constr,
00074                              ID &constrainedDOF, ID &retainedDOF)
00075 :DomainComponent(tag, CNSTRNT_TAG_MP_Constraint), 
00076  nodeRetained(nodeRetain), nodeConstrained(nodeConstr), 
00077  constraint(0), constrDOF(0), retainDOF(0), dbTag1(0), dbTag2(0)
00078 {
00079     
00080     constrDOF = new ID(constrainedDOF);
00081     retainDOF = new ID(retainedDOF);    
00082     if (constrDOF == 0 || constrainedDOF.Size() != constrDOF->Size() ||
00083         retainDOF == 0 || retainedDOF.Size() != retainDOF->Size()) { 
00084         opserr << "MP_Constraint::MP_Constraint - ran out of memory 1\n";
00085         exit(-1);
00086     }    
00087     
00088     constraint = new Matrix(constr);
00089     if (constraint == 0 || constr.noCols() != constr.noCols()) { 
00090         opserr << "MP_Constraint::MP_Constraint - ran out of memory 2\n";
00091         exit(-1);
00092     }        
00093 }
00094 
00095 
00096 
00097 MP_Constraint::~MP_Constraint()
00098 {
00099     // invoke the destructor on the matrix and the two ID objects
00100     if (constraint != 0)
00101         delete constraint;
00102     if (constrDOF != 0)
00103         delete constrDOF;
00104     if (retainDOF != 0)
00105         delete retainDOF;    
00106 }
00107 
00108 
00109 int
00110 MP_Constraint::getNodeRetained(void) const
00111 {
00112     // return id of retained node
00113     return nodeRetained;
00114 }
00115 
00116 int
00117 MP_Constraint::getNodeConstrained(void) const
00118 {
00119     // return id of constrained node    
00120     return nodeConstrained;
00121 }
00122 
00123 
00124 const ID &
00125 MP_Constraint::getConstrainedDOFs(void) const
00126 {
00127     if (constrDOF == 0) {
00128         opserr << "MP_Constraint::getConstrainedDOF - no ID was set, ";
00129         opserr << "was recvSelf() ever called? or subclass incorrect?\n";       
00130         exit(-1);
00131     }
00132 
00133     // return the ID corresponding to constrained DOF of Ccr
00134     return *constrDOF;    
00135 }
00136 
00137 
00138 const ID &
00139 MP_Constraint::getRetainedDOFs(void) const
00140 {
00141     if (retainDOF == 0) {
00142         opserr << "MP_Constraint::getRetainedDOFs - no ID was set\n ";
00143         opserr << "was recvSelf() ever called? or subclass incorrect?\n";               
00144         exit(-1);
00145     }
00146 
00147     // return the ID corresponding to retained DOF of Ccr
00148     return *retainDOF;    
00149 }
00150 
00151 int 
00152 MP_Constraint::applyConstraint(double timeStamp)
00153 {
00154     // does nothing MP_Constraint objects are time invariant
00155     return 0;
00156 }
00157 
00158 bool
00159 MP_Constraint::isTimeVarying(void) const
00160 {
00161     return false;
00162 }
00163 
00164 
00165 const Matrix &
00166 MP_Constraint::getConstraint(void)
00167 {
00168     if (constraint == 0) {
00169         opserr << "MP_Constraint::getConstraint - no Matrix was set\n";
00170         exit(-1);
00171     }    
00172 
00173     // return the constraint matrix Ccr
00174     return *constraint;    
00175 }
00176 
00177 int 
00178 MP_Constraint::sendSelf(int cTag, Channel &theChannel)
00179 {
00180     static ID data(9);
00181     int dataTag = this->getDbTag();
00182 
00183     data(0) = this->getTag(); 
00184     data(1) = nodeRetained;
00185     data(2) = nodeConstrained;
00186     if (constraint == 0) data(3) = 0; else data(3) = constraint->noRows();
00187     if (constraint == 0) data(4) = 0; else data(4) = constraint->noCols();    
00188     if (constrDOF == 0) data(5) = 0; else data(5) = constrDOF->Size();    
00189     if (retainDOF == 0) data(6) = 0; else data(6) = retainDOF->Size();        
00190     
00191     // need two database tags for ID objects
00192     if (constrDOF != 0 && dbTag1 == 0) 
00193       dbTag1 = theChannel.getDbTag();
00194     if (retainDOF != 0 && dbTag2 == 0) 
00195       dbTag2 = theChannel.getDbTag();
00196 
00197     data(7) = dbTag1;
00198     data(8) = dbTag2;
00199 
00200     int result = theChannel.sendID(dataTag, cTag, data);
00201     if (result < 0) {
00202         opserr << "WARNING MP_Constraint::sendSelf - error sending ID data\n";
00203         return result;  
00204     }    
00205     
00206     if (constraint != 0 && constraint->noRows() != 0) {
00207         int result = theChannel.sendMatrix(dataTag, cTag, *constraint);
00208         if (result < 0) {
00209             opserr << "WARNING MP_Constraint::sendSelf ";
00210             opserr << "- error sending Matrix data\n"; 
00211             return result;  
00212         }
00213     }
00214 
00215     if (constrDOF != 0 && constrDOF->Size() != 0) {
00216         int result = theChannel.sendID(dbTag1, cTag, *constrDOF);
00217         if (result < 0) {
00218             opserr << "WARNING MP_Constraint::sendSelf ";
00219             opserr << "- error sending constrained data\n"; 
00220             return result;  
00221         }
00222     }
00223 
00224     if (retainDOF != 0 && retainDOF->Size() != 0) {
00225         int result = theChannel.sendID(dbTag2, cTag, *retainDOF);
00226         if (result < 0) {
00227             opserr << "WARNING MP_Constraint::sendSelf ";
00228             opserr << "- error sending retained data\n"; 
00229             return result;  
00230         }
00231     }
00232     
00233     return 0;
00234 }
00235 
00236 
00237 int 
00238 MP_Constraint::recvSelf(int cTag, Channel &theChannel, 
00239                         FEM_ObjectBroker &theBroker)
00240 {
00241     int dataTag = this->getDbTag();
00242     static ID data(9);
00243     int result = theChannel.recvID(dataTag, cTag, data);
00244     if (result < 0) {
00245         opserr << "WARNING MP_Constraint::recvSelf - error receiving ID data\n";
00246         return result;  
00247     }    
00248 
00249     this->setTag(data(0));
00250     nodeRetained = data(1);
00251     nodeConstrained = data(2);
00252     int numRows = data(3); 
00253     int numCols = data(4);
00254     dbTag1 = data(7);
00255     dbTag2 = data(8);
00256     
00257     if (numRows != 0 && numCols != 0) {
00258         constraint = new Matrix(numRows,numCols);
00259         
00260         int result = theChannel.recvMatrix(dataTag, cTag, *constraint);
00261         if (result < 0) {
00262             opserr << "WARNING MP_Constraint::recvSelf ";
00263             opserr << "- error receiving Matrix data\n"; 
00264             return result;  
00265         }
00266     }    
00267     int size = data(5);
00268     if (size != 0) {
00269         constrDOF = new ID(size);
00270         int result = theChannel.recvID(dbTag1, cTag, *constrDOF);
00271         if (result < 0) {
00272             opserr << "WARNING MP_Constraint::recvSelf ";
00273             opserr << "- error receiving constrained data\n"; 
00274             return result;  
00275         }       
00276     }
00277     
00278     size = data(6);
00279     if (size != 0) {
00280         retainDOF = new ID(size);
00281         int result = theChannel.recvID(dbTag2, cTag, *retainDOF);
00282         if (result < 0) {
00283             opserr << "WARNING MP_Retainaint::recvSelf ";
00284             opserr << "- error receiving retained data\n"; 
00285             return result;  
00286         }       
00287     }    
00288     
00289     return 0;
00290 }
00291 
00292 
00293 
00294 void
00295 MP_Constraint::Print(OPS_Stream &s, int flag)
00296 {     
00297     s << "MP_Constraint: " << this->getTag() << "\n";
00298     s << "\tNode Constrained: " << nodeConstrained;
00299     s << " node Retained: " << nodeRetained ;
00300     if (constrDOF != 0)
00301         s << " constrained dof: " << *constrDOF;    
00302     if (retainDOF != 0)
00303         s << " retained dof: " << *retainDOF;        
00304     if (constraint != 0)
00305         s << " constraint matrix: " << *constraint << "\n";
00306 }
00307 
00308 

Generated on Mon Oct 23 15:05:00 2006 for OpenSees by doxygen 1.5.0