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

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