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

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