PenaltyConstraintHandler.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.6 $
00022 // $Date: 2005/11/29 22:04:40 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/analysis/handler/PenaltyConstraintHandler.cpp,v $
00024                                                                         
00025                                                                         
00026 // Written: fmk 
00027 // Created: May 1998
00028 // Revision: A
00029 //
00030 // What: "@(#) PenaltyConstraintHandler.C, revA"
00031 
00032 #include <PenaltyConstraintHandler.h>
00033 #include <stdlib.h>
00034 
00035 #include <AnalysisModel.h>
00036 #include <Domain.h>
00037 #include <FE_Element.h>
00038 #include <DOF_Group.h>
00039 #include <Node.h>
00040 #include <Element.h>
00041 #include <NodeIter.h>
00042 #include <ElementIter.h>
00043 #include <SP_ConstraintIter.h>
00044 #include <SP_Constraint.h>
00045 #include <MP_ConstraintIter.h>
00046 #include <MP_Constraint.h>
00047 #include <Integrator.h>
00048 #include <ID.h>
00049 #include <Subdomain.h>
00050 #include <Channel.h>
00051 #include <FEM_ObjectBroker.h>
00052 #include <PenaltySP_FE.h>
00053 #include <PenaltyMP_FE.h>
00054 
00055 
00056 PenaltyConstraintHandler::PenaltyConstraintHandler(double sp, double mp)
00057 :ConstraintHandler(HANDLER_TAG_PenaltyConstraintHandler),
00058  alphaSP(sp), alphaMP(mp)
00059 {
00060 
00061 }
00062 
00063 PenaltyConstraintHandler::~PenaltyConstraintHandler()
00064 {
00065 
00066 }
00067 
00068 int
00069 PenaltyConstraintHandler::handle(const ID *nodesLast)
00070 {
00071     // first check links exist to a Domain and an AnalysisModel object
00072     Domain *theDomain = this->getDomainPtr();
00073     AnalysisModel *theModel = this->getAnalysisModelPtr();
00074     Integrator *theIntegrator = this->getIntegratorPtr();    
00075     
00076     if ((theDomain == 0) || (theModel == 0) || (theIntegrator == 0)) {
00077         opserr << "WARNING PenaltyConstraintHandler::handle() - ";
00078         opserr << " setLinks() has not been called\n";
00079         return -1;
00080     }
00081 
00082     
00083     // get number ofelements and nodes in the domain 
00084     // and init the theFEs and theDOFs arrays
00085     int numSPs = 0;
00086     SP_ConstraintIter &theSPs = theDomain->getDomainAndLoadPatternSPs();
00087     SP_Constraint *spPtr;
00088     while ((spPtr = theSPs()) != 0)
00089       numSPs++;
00090     
00091     // initialse the DOF_Groups and add them to the AnalysisModel.
00092     //    : must of course set the initial IDs
00093     NodeIter &theNod = theDomain->getNodes();
00094     Node *nodPtr;
00095     MP_Constraint *mpPtr;    
00096     DOF_Group *dofPtr;
00097     
00098     int numDofGrp = 0;
00099     int count3 = 0;
00100     int countDOF =0;
00101     while ((nodPtr = theNod()) != 0) {
00102         if ((dofPtr = new DOF_Group(numDofGrp++, nodPtr)) == 0) {
00103             opserr << "WARNING PenaltyConstraintHandler::handle() ";
00104             opserr << "- ran out of memory";
00105             opserr << " creating DOF_Group " << numDofGrp << endln;     
00106             return -4;                  
00107         }
00108 
00109         // initially set all the ID value to -2
00110         const ID &id = dofPtr->getID();
00111         for (int j=0; j < id.Size(); j++) {
00112             dofPtr->setID(j,-2);
00113             countDOF++;
00114         }
00115         nodPtr->setDOF_GroupPtr(dofPtr);
00116         theModel->addDOF_Group(dofPtr);
00117     }
00118 
00119     theModel->setNumEqn(countDOF);
00120 
00121     // set the number of eqn in the model
00122     // now see if we have to set any of the dof's to -3
00123     //    int numLast = 0;
00124     if (nodesLast != 0) 
00125         for (int i=0; i<nodesLast->Size(); i++) {
00126             int nodeID = (*nodesLast)(i);
00127             Node *nodPtr = theDomain->getNode(nodeID);
00128             if (nodPtr != 0) {
00129                 dofPtr = nodPtr->getDOF_GroupPtr();
00130                 
00131                 const ID &id = dofPtr->getID();
00132                 // set all the dof values to -3
00133                 for (int j=0; j < id.Size(); j++) 
00134                     if (id(j) == -2) {
00135                         dofPtr->setID(j,-3);
00136                         count3++;
00137                     } else {
00138                         opserr << "WARNING PenaltyConstraintHandler::handle() ";
00139                         opserr << " - boundary sp constraint in subdomain";
00140                         opserr << " this should not be - results suspect \n";
00141                     }
00142             }
00143         }
00144 
00145     // create the FE_Elements for the Elements and add to the AnalysisModel
00146     ElementIter &theEle = theDomain->getElements();
00147     Element *elePtr;
00148 
00149     int numFeEle = 0;
00150     FE_Element *fePtr;
00151     while ((elePtr = theEle()) != 0) {
00152 
00153       // only create an FE_Element for a subdomain element if it does not
00154       // do independent analysis .. then subdomain part of this analysis so create
00155       // an FE_element & set subdomain to point to it.
00156       if (elePtr->isSubdomain() == true) {
00157         Subdomain *theSub = (Subdomain *)elePtr;
00158         if (theSub->doesIndependentAnalysis() == false) {
00159           if ((fePtr = new FE_Element(numFeEle++, elePtr)) == 0) {
00160             opserr << "WARNING PlainHandler::handle() - ran out of memory";
00161             opserr << " creating FE_Element " << elePtr->getTag() << endln; 
00162             return -5;
00163           }             
00164 
00165           theModel->addFE_Element(fePtr);
00166           theSub->setFE_ElementPtr(fePtr);
00167 
00168         } //  if (theSub->doesIndependentAnalysis() == false) {
00169 
00170       } else {
00171         
00172         // just a regular element .. create an FE_Element for it & add to AnalysisModel
00173         if ((fePtr = new FE_Element(numFeEle++, elePtr)) == 0) {
00174           opserr << "WARNING PlainHandler::handle() - ran out of memory";
00175           opserr << " creating FE_Element " << elePtr->getTag() << endln; 
00176           return -5;
00177         }
00178         
00179         theModel->addFE_Element(fePtr);
00180       }
00181     }
00182     
00183 
00184     // create the PenaltySP_FE for the SP_Constraints and 
00185     // add to the AnalysisModel
00186     SP_ConstraintIter &theSPss = theDomain->getDomainAndLoadPatternSPs();
00187     while ((spPtr = theSPss()) != 0) {
00188         if ((fePtr = new PenaltySP_FE(numFeEle, *theDomain, *spPtr, alphaSP)) == 0) {
00189             opserr << "WARNING PenaltyConstraintHandler::handle()";
00190             opserr << " - ran out of memory";
00191             opserr << " creating PenaltySP_FE " << endln; 
00192             return -5;
00193         }               
00194         theModel->addFE_Element(fePtr);
00195         numFeEle++;
00196     }       
00197 
00198     // create the PenaltyMP_FE for the MP_Constraints and 
00199     // add to the AnalysisModel    
00200 
00201     MP_ConstraintIter &theMPs = theDomain->getMPs();
00202     while ((mpPtr = theMPs()) != 0) {
00203         if ((fePtr = new PenaltyMP_FE(numFeEle, *theDomain, *mpPtr, alphaMP)) == 0) {
00204             opserr << "WARNING PenaltyConstraintHandler::handle()";
00205             opserr << " - ran out of memory";
00206             opserr << " creating PenaltyMP_FE " << endln; 
00207             return -5;
00208         }               
00209         theModel->addFE_Element(fePtr);
00210         numFeEle++;
00211     }           
00212     
00213     return count3;
00214 }
00215 
00216 
00217 void 
00218 PenaltyConstraintHandler::clearAll(void)
00219 {
00220     // for the nodes reset the DOF_Group pointers to 0
00221     Domain *theDomain = this->getDomainPtr();
00222     if (theDomain == 0)
00223         return;
00224 
00225     NodeIter &theNod = theDomain->getNodes();
00226     Node *nodPtr;
00227     while ((nodPtr = theNod()) != 0)
00228         nodPtr->setDOF_GroupPtr(0);
00229 }    
00230 
00231 int
00232 PenaltyConstraintHandler::sendSelf(int cTag, Channel &theChannel)
00233 {
00234   Vector data(2);
00235   int result = 0;
00236   data(0) = alphaSP;
00237   data(1) = alphaMP;
00238   result = theChannel.sendVector(this->getDbTag(), cTag, data);
00239   if (result != 0) 
00240     opserr << "PenaltyConstraintHandler::sendSelf() - error sending Vector\n";
00241   return result;
00242 }
00243 
00244 int
00245 PenaltyConstraintHandler::recvSelf(int cTag, 
00246                                    Channel &theChannel, 
00247                                    FEM_ObjectBroker &theBroker)  
00248 {
00249   Vector data(2);
00250   int result = 0;
00251   result = theChannel.recvVector(this->getDbTag(), cTag, data);
00252   alphaSP = data(0);
00253   alphaMP = data(1);
00254   if (result != 0) 
00255     opserr << "PenaltyConstraintHandler::recvSelf() - error receiving Vector\n";
00256   return result;
00257 }

Generated on Mon Oct 23 15:04:58 2006 for OpenSees by doxygen 1.5.0