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

AnalysisModel.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/03 06:13:22 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/analysis/model/AnalysisModel.cpp,v $
00024                                                                         
00025                                                                         
00026 // File: ~/analysis/model/AnalysisModel.C
00027 //
00028 // Written: fmk 
00029 // Created: Fri Sep 20 15:27:47: 1996
00030 // Revision: A
00031 //
00032 // Purpose: This file contains the class definition for AnalysisModel
00033 // AnalysisModel is a container class. The class is responsible for holding
00034 // and providing access to the Elements, Nodes, LoadCases, SP_Constraints 
00035 // and MP_Constraints. These objects are all added to the AnalysisModel by a 
00036 // ModelBuilder.
00037 //
00038 // What: "@(#) AnalysisModel.C, revA"
00039 
00040 #include <stdlib.h>
00041 
00042 #include <AnalysisModel.h>
00043 #include <Domain.h>
00044 #include <FE_Element.h>
00045 #include <DOF_Group.h>
00046 #include <DOF_GrpIter.h>
00047 #include <FE_EleIter.h>
00048 #include <DOF_Graph.h>
00049 #include <DOF_GroupGraph.h>
00050 #include <Node.h>
00051 #include <NodeIter.h>
00052 
00053 //  AnalysisModel();
00054 // constructor
00055 
00056 AnalysisModel::AnalysisModel(int theClassTag)
00057 :MovableObject(theClassTag),
00058  myDomain(0), myDOFGraph(0), myGroupGraph(0),
00059  numFE_Ele(0), numDOF_Grp(0), numEqn(0),
00060  theFEs(0), theDOFs(0),
00061  theFEiter(*this), theDOFiter(*this)
00062 {
00063     // for subclasses to use - they provide own container stuff
00064 } 
00065 
00066 AnalysisModel::AnalysisModel()
00067 :MovableObject(AnaMODEL_TAGS_AnalysisModel),
00068  myDomain(0), myDOFGraph(0), myGroupGraph(0),
00069  numFE_Ele(0), numDOF_Grp(0), numEqn(0),
00070  theFEs(0), theDOFs(0),
00071  theFEiter(*this), theDOFiter(*this)
00072 {
00073   sizeEle = 256;  // these arrays get enlarged as needed
00074   sizeDOF = 256;
00075 
00076   theFEs = new FE_Element *[sizeEle];
00077   if (theFEs == 0) {
00078       cerr << "FATAL:AnalysisModel::AnalysisModel()";
00079       cerr << " ran out of memory creating array for FE_Elements\n";
00080       exit(-1);
00081   }
00082   for (int i=0; i<sizeEle; i++) theFEs[i] = 0;
00083 
00084   theDOFs = new DOF_Group *[sizeDOF];
00085   if (theDOFs == 0) {
00086       cerr << "FATAL:AnalysisModel::AnalysisModel()";
00087       cerr << " ran out of memory creating array for DOF_Groups\n";
00088       exit(-1);
00089   }
00090   for (int j=0; j<sizeDOF; j++) theDOFs[j] = 0;
00091 } 
00092 
00093 
00094 // ~AnalysisModel();    
00095 AnalysisModel::~AnalysisModel()
00096 {
00097     if (theFEs != 0)
00098  delete [] theFEs;
00099 
00100     if (theDOFs != 0)
00101  delete [] theDOFs;
00102 
00103     if (myGroupGraph != 0) {
00104  delete myGroupGraph;    
00105     } 
00106 
00107     if (myDOFGraph != 0) {
00108  delete myDOFGraph;
00109     }
00110 }    
00111 
00112 void
00113 AnalysisModel::setLinks(Domain &theDomain)
00114 {
00115     myDomain = &theDomain;
00116 }
00117 
00118 
00119 // void addFE_Element(FE_Element *);
00120 // Method to add an element to the model.
00121 
00122 bool
00123 AnalysisModel::addFE_Element(FE_Element *theElement)
00124 {
00125 
00126   // check we don't add a null pointer or this is a subclass
00127   // trying to use this method when it should'nt
00128   if (theElement == 0 || theFEs == 0)
00129       return false;
00130   
00131   // see if the current theFEs array is big enough, if not double
00132   // it's size by making a new one, copying the pointers and deleting old.
00133   if (numFE_Ele == sizeEle) { // we have to expand our componentArray array
00134       int newArraySize = 2 * sizeEle;
00135       FE_Element **newArray = new FE_Element *[newArraySize];
00136       if (newArray == 0) {
00137    cerr << "AnalysisModel::addFE_Element -";
00138    cerr << "could not allocate enough memory for new array\n";
00139    exit(-1);
00140       }
00141       
00142       int i;
00143       for (i=0; i<newArraySize; i++)
00144  newArray[i] = 0;
00145 
00146       for (i=0; i<sizeEle; i++)
00147  newArray[i] = theFEs[i];
00148 
00149       delete  [] theFEs;
00150       theFEs = newArray;
00151       sizeEle = newArraySize;
00152   }
00153 
00154   // put the FE_Element into the list
00155 
00156   theFEs[numFE_Ele] = theElement;
00157   theElement->setAnalysisModel(*this);
00158   numFE_Ele++;
00159 
00160   return true;  // o.k.
00161 }
00162 
00163 
00164 
00165 
00166 // void addDOF_Group(DOF_Group *);
00167 // Method to add an element to the model.
00168 
00169 bool
00170 AnalysisModel::addDOF_Group(DOF_Group *theDOF_Group)
00171 {
00172 
00173   // check we don't add a null pointer or this is a subclass trying
00174   // to use a method it should'nt be using
00175   if (theDOF_Group == 0 || theDOFs == 0)
00176       return false;
00177   
00178   // see if the current theFEs array is big enough, if not double
00179   // it's size by making a new one, copying the pointers and deleting old.
00180 
00181   if (numDOF_Grp == sizeDOF) { // we have to expand our componentArray array
00182       int newArraySize = 2 * sizeDOF;
00183       DOF_Group **newArray = new DOF_Group *[newArraySize];
00184       if (newArray == 0) {
00185    cerr << "AnalysisModel::addDOF_Group -";
00186    cerr << "could not allocate enough memory for new array\n";
00187    exit(-1);
00188       }      
00189       int i;
00190       for (i=0; i<newArraySize; i++)
00191  newArray[i] = 0;
00192 
00193       for (i=0; i<sizeDOF; i++)
00194  newArray[i] = theDOFs[i];
00195 
00196       delete  [] theDOFs;
00197       theDOFs = newArray;
00198       sizeDOF = newArraySize;
00199   }
00200 
00201   // put the DOF_Group into the list
00202 
00203   theDOFs[numDOF_Grp] = theDOF_Group;
00204   numDOF_Grp++;
00205   return true;  // o.k.
00206 }
00207 
00208 void
00209 AnalysisModel::clearAll(void) 
00210 {
00211     // if the graphs have been constructed delete them
00212     if (myDOFGraph != 0)
00213  delete myDOFGraph;
00214 
00215     if (myGroupGraph != 0)
00216  delete myGroupGraph;    
00217 
00218     myDOFGraph = 0;
00219     myGroupGraph = 0;
00220     
00221     // remove the FE_Elements
00222     // they are not deleted as the ConstraintHandler may 
00223     // be able to reuse them
00224     for (int i=0; i<sizeEle; i++) {
00225  theFEs[i] = 0;
00226     }
00227 
00228     // remove the DOF_Groups 
00229     // they are not deleted as the ConstraintHandler may 
00230     // be able to reuse them.    
00231     for (int j=0; j<sizeDOF; j++) {
00232  theDOFs[j] =0;
00233     }
00234 
00235     numFE_Ele =0;
00236     numDOF_Grp = 0;
00237     numEqn = 0;    
00238 }
00239 
00240 
00241 
00242 
00243 int
00244 AnalysisModel::getNumDOF_Groups(void) const
00245 {
00246     return numDOF_Grp;
00247 }
00248 
00249 
00250 DOF_Group *
00251 AnalysisModel::getDOF_GroupPtr(int tag)
00252 {
00253     // check to see if in a simple position
00254     // this will be the case if DOF_Groups are created and added in order
00255     // which will probably be the typical situation (note true if DOF tags 
00256     // start from 0)
00257     if (tag < numDOF_Grp && tag > 0)
00258  if ((theDOFs[tag]->getTag()) == tag)
00259      return theDOFs[tag];
00260 
00261     // else we have to search through and check till we find it
00262     for (int i=0; i<numDOF_Grp; i++)
00263  if ((theDOFs[i]->getTag()) == tag)
00264      return theDOFs[i];
00265     
00266     return 0;
00267 }
00268 
00269 
00270 FE_EleIter &
00271 AnalysisModel::getFEs()
00272 {
00273     theFEiter.reset();
00274     return theFEiter;
00275 }
00276 
00277 DOF_GrpIter &
00278 AnalysisModel::getDOFs()
00279 {
00280     theDOFiter.reset();
00281     return theDOFiter;
00282 }
00283 
00284 void 
00285 AnalysisModel::setNumEqn(int theNumEqn)
00286 {
00287     numEqn = theNumEqn;
00288 }
00289 
00290 int 
00291 AnalysisModel::getNumEqn(void) const
00292 {
00293     return numEqn;
00294 }
00295 
00296 
00297 Graph &
00298 AnalysisModel::getDOFGraph(void)
00299 {
00300   if (myDOFGraph == 0) 
00301  myDOFGraph = new DOF_Graph(*this);
00302   return *myDOFGraph;
00303 }
00304 
00305 
00306 Graph &
00307 AnalysisModel::getDOFGroupGraph(void)
00308 {
00309     if (myGroupGraph == 0)
00310  myGroupGraph = new DOF_GroupGraph(*this);
00311     return *myGroupGraph;
00312 }
00313 
00314 
00315 
00316 
00317 void 
00318 AnalysisModel::setResponse(const Vector &disp,
00319       const Vector &vel, 
00320       const Vector &accel)
00321 {
00322     DOF_GrpIter &theDOFGrps = this->getDOFs();
00323     DOF_Group  *dofPtr;
00324     
00325     while ((dofPtr = theDOFGrps()) != 0) {
00326  dofPtr->setNodeDisp(disp);
00327  dofPtr->setNodeVel(vel);
00328  dofPtr->setNodeAccel(accel); 
00329     }
00330 } 
00331  
00332 void 
00333 AnalysisModel::setDisp(const Vector &disp)
00334 {
00335     DOF_GrpIter &theDOFGrps = this->getDOFs();
00336     DOF_Group  *dofPtr;
00337 
00338     while ((dofPtr = theDOFGrps()) != 0) 
00339  dofPtr->setNodeDisp(disp);
00340 } 
00341  
00342 void 
00343 AnalysisModel::setVel(const Vector &vel)
00344 {
00345         DOF_GrpIter &theDOFGrps = this->getDOFs();
00346     DOF_Group  *dofPtr;
00347     
00348     while ((dofPtr = theDOFGrps()) != 0) 
00349  dofPtr->setNodeVel(vel);
00350 } 
00351  
00352 
00353 void 
00354 AnalysisModel::setAccel(const Vector &accel)
00355 {
00356     DOF_GrpIter &theDOFGrps = this->getDOFs();
00357     DOF_Group  *dofPtr;
00358     
00359     while ((dofPtr = theDOFGrps()) != 0) 
00360  dofPtr->setNodeAccel(accel); 
00361 } 
00362 
00363 void 
00364 AnalysisModel::incrDisp(const Vector &disp)
00365 {
00366     DOF_GrpIter &theDOFGrps = this->getDOFs();
00367     DOF_Group  *dofPtr;
00368 
00369     while ((dofPtr = theDOFGrps()) != 0) 
00370  dofPtr->incrNodeDisp(disp);
00371 } 
00372  
00373 void 
00374 AnalysisModel::incrVel(const Vector &vel)
00375 {
00376         DOF_GrpIter &theDOFGrps = this->getDOFs();
00377     DOF_Group  *dofPtr;
00378     
00379     while ((dofPtr = theDOFGrps()) != 0) 
00380  dofPtr->incrNodeVel(vel);
00381 } 
00382  
00383 void 
00384 AnalysisModel::incrAccel(const Vector &accel)
00385 {
00386     DOF_GrpIter &theDOFGrps = this->getDOFs();
00387     DOF_Group  *dofPtr;
00388     
00389     while ((dofPtr = theDOFGrps()) != 0) 
00390  dofPtr->incrNodeAccel(accel); 
00391 } 
00392 
00393 
00394 void 
00395 AnalysisModel::setNumEigenvectors(int numEigenvectors)
00396 {
00397     Node *theNode;
00398     NodeIter &theNodes = myDomain->getNodes();
00399     while ((theNode = theNodes()) != 0)
00400  theNode->setNumEigenvectors(numEigenvectors);
00401 } 
00402 
00403 void 
00404 AnalysisModel::setEigenvalues(const Vector &eigenvalues)
00405 {
00406     myDomain->setEigenvalues(eigenvalues);
00407 } 
00408 
00409 void 
00410 AnalysisModel::setEigenvector(int mode, const Vector &eigenvalue)
00411 {
00412     DOF_GrpIter &theDOFGrps = this->getDOFs();
00413     DOF_Group  *dofPtr;
00414     
00415     while ((dofPtr = theDOFGrps()) != 0) 
00416  dofPtr->setEigenvector(mode, eigenvalue); 
00417 } 
00418 
00419 void 
00420 AnalysisModel::applyLoadDomain(double pseudoTime)
00421 {
00422     // check to see there is a Domain linked to the Model
00423 
00424     if (myDomain == 0) {
00425  cerr << "WARNING: AnalysisModel::applyLoadDomain. No Domain linked.\n";
00426  return;
00427     }
00428 
00429     // invoke the method
00430     myDomain->applyLoad(pseudoTime);
00431 }
00432 
00433 void 
00434 AnalysisModel::updateDomain(void)
00435 {
00436     // check to see there is a Domain linked to the Model
00437 
00438     if (myDomain == 0) {
00439  cerr << "WARNING: AnalysisModel::commitDomain. No Domain linked.\n";
00440  return;
00441     }
00442 
00443     // invoke the method
00444     myDomain->update();
00445 }
00446 
00447 
00448 int
00449 AnalysisModel::commitDomain(void)
00450 {
00451     // check to see there is a Domain linked to the Model
00452     if (myDomain == 0) {
00453  cerr << "WARNING: AnalysisModel::commitDomain. No Domain linked.\n";
00454  return -1;
00455     }
00456 
00457     // invoke the method
00458     if (myDomain->commit() < 0) {
00459  cerr << "WARNING: AnalysisModel::commitDomain - Domain::commit() failed\n";
00460  return -2;
00461     } 
00462 
00463     return 0;
00464 }
00465 
00466 int
00467 AnalysisModel::revertDomainToLastCommit(void)
00468 {
00469     // check to see there is a Domain linked to the Model
00470 
00471     if (myDomain == 0) {
00472  cerr << "WARNING: AnalysisModel::commitDomainToLastCommit.";
00473  cerr << " No Domain linked.\n";
00474  return -1;
00475     }
00476 
00477     // invoke the method
00478     if (myDomain->revertToLastCommit() < 0) {
00479  cerr << "WARNING: AnalysisModel::revertDomainToLastCommit.";
00480  cerr << " Domain::revertToLastCommit() failed.\n";
00481  return -2;
00482     } 
00483     return 0;
00484 }
00485 
00486 double
00487 AnalysisModel::getCurrentDomainTime(void)
00488 {
00489     // check to see there is a Domain linked to the Model
00490 
00491     if (myDomain == 0) {
00492  cerr << "WARNING: AnalysisModel::getCurrentDomainTime.";
00493  cerr << " No Domain linked.\n";
00494  return 0.0;
00495     }
00496 
00497     // invoke the method
00498     return myDomain->getCurrentTime();
00499 }
00500 
00501 
00502 void
00503 AnalysisModel::setCurrentDomainTime(double newTime)
00504 {
00505     if (myDomain == 0) {
00506  cerr << "WARNING: AnalysisModel::getCurrentDomainTime.";
00507  cerr << " No Domain linked.\n";
00508     }
00509 
00510     // invoke the method
00511     myDomain->setCurrentTime(newTime);
00512 }
00513 
00514 
00515 
00516 
00517 Domain *
00518 AnalysisModel::getDomainPtr(void) const
00519 {
00520     return myDomain;
00521 }
00522 
00523 
00524 int
00525 AnalysisModel::sendSelf(int cTag, Channel &theChannel)
00526 {
00527     return 0;
00528 }
00529 
00530 
00531 int
00532 AnalysisModel::recvSelf(int cTag, Channel &theChannel, 
00533    FEM_ObjectBroker &theBroker) 
00534 {
00535     return 0;
00536 }
00537 
Copyright Contact Us