Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

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