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

Domain.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: 2001/05/18 04:51:55 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/domain/domain/Domain.cpp,v $
00024                                                                         
00025                                                                         
00026 // FileP: ~/domain/domain/Domain.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 Domain
00033 // Domain 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 Domain by a 
00036 // ModelBuilder.
00037 //
00038 // What: "@(#) Domain.C, revA"
00039 
00040 #include <stdlib.h>
00041 
00042 #include <G3Globals.h>
00043 #include <Domain.h>
00044 
00045 #include <ElementIter.h>
00046 #include <NodeIter.h>
00047 #include <ElementalLoadIter.h>
00048 #include <NodalLoadIter.h>
00049 #include <Element.h>
00050 #include <Node.h>
00051 #include <SP_Constraint.h>
00052 #include <MP_Constraint.h>
00053 #include <NodalLoad.h>
00054 #include <ElementalLoad.h>
00055 #include <LoadPattern.h>
00056 
00057 #include <ArrayOfTaggedObjects.h>
00058 #include <ArrayOfTaggedObjectsIter.h>
00059 
00060 #include <SingleDomEleIter.h>
00061 #include <SingleDomNodIter.h>
00062 #include <SingleDomSP_Iter.h>
00063 #include <SingleDomMP_Iter.h>
00064 #include <LoadPatternIter.h>
00065 #include <SingleDomAllSP_Iter.h>
00066 
00067 #include <Vertex.h>
00068 #include <Graph.h>
00069 #include <Recorder.h>
00070 #include <Analysis.h>
00071 #include <FE_Datastore.h>
00072 #include <FEM_ObjectBroker.h>
00073 
00074 Domain::Domain()
00075 :currentTime(0.0), committedTime(0.0), currentGeoTag(0),
00076  hasDomainChangedFlag(false), theDbTag(0), lastGeoSendTag(-1),
00077  dbEle(0), dbNod(0), dbSPs(0), dbMPs(0), dbLPs(0),
00078  eleGraphBuiltFlag(false),  nodeGraphBuiltFlag(false), theNodeGraph(0), 
00079  theElementGraph(0), 
00080  theRecorders(0), numRecorders(0), commitTag(0),
00081  theBounds(6), theEigenvalues(0), theEigenvalueSetTime(0)
00082 {
00083     // init the arrays for storing the domain components
00084     theElements = new ArrayOfTaggedObjects(4096);
00085     theNodes    = new ArrayOfTaggedObjects(4096);
00086     theSPs      = new ArrayOfTaggedObjects(256);
00087     theMPs      = new ArrayOfTaggedObjects(256);    
00088     theLoadPatterns = new ArrayOfTaggedObjects(32);
00089 
00090     // init the iters    
00091     theEleIter = new SingleDomEleIter(theElements);    
00092     theNodIter = new SingleDomNodIter(theNodes);
00093     theSP_Iter = new SingleDomSP_Iter(theSPs);
00094     theMP_Iter = new SingleDomMP_Iter(theMPs);
00095     theLoadPatternIter = new LoadPatternIter(theLoadPatterns);
00096     allSP_Iter = new SingleDomAllSP_Iter(*this);
00097     
00098     // check that there was space to create the data structures    
00099     if (theElements ==0 || theNodes == 0 || 
00100  theSPs == 0 || theMPs == 0 || 
00101  theEleIter == 0 || theNodIter == 0 || 
00102  theMP_Iter == 0 || theSP_Iter == 0 ||
00103  theLoadPatterns == 0 || theLoadPatternIter == 0) { 
00104 
00105  g3ErrorHandler->fatal("Domain::Domain() - out of memory\n");
00106     }
00107     
00108     theBounds(0) = 0;
00109     theBounds(1) = 0;
00110     theBounds(2) = 0;
00111     theBounds(3) = 0;
00112     theBounds(4) = 0;    
00113     theBounds(5) = 0;            
00114 }
00115 
00116 
00117 Domain::Domain(int numNodes, int numElements, int numSPs, int numMPs,
00118         int numLoadPatterns)
00119 :currentTime(0.0), committedTime(0.0), currentGeoTag(0),
00120  hasDomainChangedFlag(false), theDbTag(0), lastGeoSendTag(-1),
00121  dbEle(0), dbNod(0), dbSPs(0), dbMPs(0), dbLPs(0),
00122  eleGraphBuiltFlag(false), nodeGraphBuiltFlag(false), theNodeGraph(0), 
00123  theElementGraph(0),
00124  theRecorders(0), numRecorders(0), commitTag(0),
00125  theBounds(6), theEigenvalues(0), theEigenvalueSetTime(0)
00126 {
00127     // init the arrays for storing the domain components
00128     theElements = new ArrayOfTaggedObjects(numElements);
00129     theNodes    = new ArrayOfTaggedObjects(numNodes);
00130     theSPs      = new ArrayOfTaggedObjects(numSPs);
00131     theMPs      = new ArrayOfTaggedObjects(numMPs);    
00132     theLoadPatterns = new ArrayOfTaggedObjects(numLoadPatterns);
00133     
00134     // init the iters
00135     theEleIter = new SingleDomEleIter(theElements);    
00136     theNodIter = new SingleDomNodIter(theNodes);
00137     theSP_Iter = new SingleDomSP_Iter(theSPs);
00138     theMP_Iter = new SingleDomMP_Iter(theMPs);
00139     theLoadPatternIter = new LoadPatternIter(theLoadPatterns);
00140     allSP_Iter = new SingleDomAllSP_Iter(*this);
00141     
00142     // check that there was space to create the data structures    
00143     if (theElements ==0 || theNodes == 0 || 
00144  theSPs == 0 || theMPs == 0 || 
00145  theEleIter == 0 || theNodIter == 0 || 
00146  theMP_Iter == 0 || theSP_Iter == 0 ||
00147  theLoadPatterns == 0 || theLoadPatternIter == 0) { 
00148 
00149  g3ErrorHandler->fatal("Domain::Domain(int, int, ...) - out of memory\n");
00150     }
00151     
00152     theBounds(0) = 0;
00153     theBounds(1) = 0;
00154     theBounds(2) = 0;
00155     theBounds(3) = 0;
00156     theBounds(4) = 0;    
00157     theBounds(5) = 0;            
00158 }
00159 
00160 
00161 Domain::Domain(TaggedObjectStorage &theNodesStorage,
00162         TaggedObjectStorage &theElementsStorage,
00163         TaggedObjectStorage &theMPsStorage,
00164         TaggedObjectStorage &theSPsStorage,
00165         TaggedObjectStorage &theLoadPatternsStorage)
00166 :currentTime(0.0), committedTime(0.0), currentGeoTag(0),
00167  hasDomainChangedFlag(false), theDbTag(0), lastGeoSendTag(-1),
00168  dbEle(0), dbNod(0), dbSPs(0), dbMPs(0), dbLPs(0),
00169  eleGraphBuiltFlag(false), nodeGraphBuiltFlag(false), theNodeGraph(0), 
00170  theElementGraph(0), 
00171  theElements(&theElementsStorage),
00172  theNodes(&theNodesStorage),
00173  theSPs(&theSPsStorage),
00174  theMPs(&theMPsStorage), 
00175  theLoadPatterns(&theLoadPatternsStorage),
00176  theRecorders(0), numRecorders(0), commitTag(0),
00177  theBounds(6), theEigenvalues(0), theEigenvalueSetTime(0)
00178 {
00179     // init the iters    
00180     theEleIter = new SingleDomEleIter(theElements);    
00181     theNodIter = new SingleDomNodIter(theNodes);
00182     theSP_Iter = new SingleDomSP_Iter(theSPs);
00183     theMP_Iter = new SingleDomMP_Iter(theMPs);
00184     theLoadPatternIter = new LoadPatternIter(theLoadPatterns);
00185     allSP_Iter = new SingleDomAllSP_Iter(*this);
00186 
00187     // check that the containers are empty
00188     if (theElements->getNumComponents() != 0 ||
00189  theNodes->getNumComponents() != 0 ||
00190  theSPs->getNumComponents() != 0 ||
00191  theMPs->getNumComponents() != 0 ||
00192  theLoadPatterns->getNumComponents() != 0 ) {
00193 
00194  g3ErrorHandler->fatal("Domain::Domain(&, & ...) - out of memory\n"); 
00195     }     
00196  
00197     // check that there was space to create the data structures    
00198     if (theElements ==0 || theNodes == 0 || 
00199  theSPs == 0 || theMPs == 0 || 
00200  theEleIter == 0 || theNodIter == 0 ||
00201  theMP_Iter == 0 || theSP_Iter == 0 ||
00202  theLoadPatterns == 0 || theLoadPatternIter == 0) { 
00203     
00204  cerr << "FATAL Domain::Domain(TaggedObjectStorage, ...) - ";
00205  cerr << "Ran out of memory\n";
00206  exit(-1);
00207     }    
00208     
00209     theBounds(0) = 0;
00210     theBounds(1) = 0;
00211     theBounds(2) = 0;
00212     theBounds(3) = 0;
00213     theBounds(4) = 0;    
00214     theBounds(5) = 0;            
00215 }    
00216 
00217 
00218 
00219 Domain::Domain(TaggedObjectStorage &theStorage)
00220 :currentTime(0.0), committedTime(0.0), currentGeoTag(0),
00221  hasDomainChangedFlag(false), theDbTag(0), lastGeoSendTag(-1),
00222  dbEle(0), dbNod(0), dbSPs(0), dbMPs(0), dbLPs(0),
00223  eleGraphBuiltFlag(false), nodeGraphBuiltFlag(false), theNodeGraph(0), 
00224  theElementGraph(0), 
00225  theRecorders(0), numRecorders(0), commitTag(0),
00226  theBounds(6), theEigenvalues(0), theEigenvalueSetTime(0)
00227 {
00228     // init the arrays for storing the domain components
00229     theStorage.clearAll(); // clear the storage just in case populated
00230     theElements = &theStorage;
00231     theNodes    = theStorage.getEmptyCopy();
00232     theSPs      = theStorage.getEmptyCopy();
00233     theMPs      = theStorage.getEmptyCopy();
00234     theLoadPatterns = theStorage.getEmptyCopy();    
00235 
00236     // init the iters    
00237     theEleIter = new SingleDomEleIter(theElements);    
00238     theNodIter = new SingleDomNodIter(theNodes);
00239     theSP_Iter = new SingleDomSP_Iter(theSPs);
00240     theMP_Iter = new SingleDomMP_Iter(theMPs);
00241     theLoadPatternIter = new LoadPatternIter(theLoadPatterns);
00242     allSP_Iter = new SingleDomAllSP_Iter(*this);
00243 
00244     // check that there was space to create the data structures    
00245     if (theElements ==0 || theNodes == 0 || 
00246  theSPs == 0 || theMPs == 0 || 
00247  theEleIter == 0 || theNodIter == 0 ||
00248  theMP_Iter == 0 || theSP_Iter == 0 ||
00249  theLoadPatterns == 0 || theLoadPatternIter == 0) { 
00250  
00251  g3ErrorHandler->fatal("Domain::Domain(ObjectStorage &) - out of memory\n"); 
00252     }
00253     
00254     theBounds(0) = 0;
00255     theBounds(1) = 0;
00256     theBounds(2) = 0;
00257     theBounds(3) = 0;
00258     theBounds(4) = 0;    
00259     theBounds(5) = 0;            
00260 }
00261 
00262 
00263 
00264 
00265 
00266 // ~Domain();    
00267 // destructor, this calls delete on all components of the model,
00268 // i.e. calls delete on all that is added to the model.
00269 // WARNING: if 3rd constructor, TaggedObjectStorage objects passed 
00270 //      must have been created with new and nowhere else must the
00271 //      destructor be called.
00272 
00273 Domain::~Domain()
00274 {
00275     // delete all the storage objects
00276     // SEGMENT FAULT WILL OCCUR IF THESE OBJECTS WERE NOT CONSTRUCTED
00277     // USING NEW
00278     if (theElements != 0)
00279  delete theElements;    
00280 
00281     if (theNodes != 0)
00282  delete theNodes;
00283 
00284     if (theSPs != 0)
00285  delete theSPs;
00286 
00287     if (theMPs != 0)
00288  delete theMPs;
00289 
00290     if (theLoadPatterns != 0)
00291  delete theLoadPatterns;
00292     
00293     if (theEleIter != 0)
00294  delete theEleIter;
00295     
00296     if (theNodIter != 0)
00297  delete theNodIter;
00298     
00299     if (theSP_Iter != 0)
00300  delete theSP_Iter;
00301     
00302     if (theMP_Iter != 0)
00303  delete theMP_Iter;
00304 
00305     if (allSP_Iter != 0)
00306  delete allSP_Iter;
00307 
00308     if (theEigenvalues != 0)
00309       delete theEigenvalues;
00310 
00311     for (int i=0; i<numRecorders; i++)  
00312       delete theRecorders[i];
00313     
00314     if (theRecorders != 0) {
00315  free((void *)theRecorders);
00316  theRecorders = 0;
00317     }
00318   
00319     theRecorders = 0;
00320     numRecorders = 0;
00321 }
00322 
00323 
00324 // void addElement(Element *);
00325 // Method to add an element to the model.
00326 
00327 
00328 bool
00329 Domain::addElement(Element *element)
00330 {
00331   int eleTag = element->getTag();
00332 
00333 #ifdef _G3DEBUG
00334   // check all the elements nodes exist in the domain
00335   const ID &nodes = element->getExternalNodes();
00336   int numDOF = 0;
00337   for (int i=0; i<nodes.Size(); i++) {
00338       int nodeTag = nodes(i);
00339       Node *nodePtr = this->getNode(nodeTag);
00340       if (nodePtr == 0) {
00341    cerr << "WARNING Domain::addElement - In element " << *element;
00342    cerr << "\n no Node " << nodeTag << " exists in the domain\n";
00343    return false;
00344       }
00345       numDOF += nodePtr->getNumberDOF();
00346   }   
00347 #endif
00348 
00349   // check if an Element with a similar tag already exists in the Domain
00350   TaggedObject *other = theElements->getComponentPtr(eleTag);
00351   if (other != 0) {
00352       g3ErrorHandler->warning("Domain::addElement - element with tag %d %s\n",
00353          eleTag,
00354          "already exists in model"); 
00355 
00356       return false;
00357   }
00358 
00359   // add the element to the container object for the elements
00360   bool result = theElements->addComponent(element);
00361   if (result == true) {
00362    element->setDomain(this);
00363 
00364       // finally check the ele has correct number of dof
00365 #ifdef _G3DEBUG
00366       if (numDOF != element->getNumDOF()) { 
00367 
00368    g3ErrorHandler->warning("Domain::addElement - element %d %s\n",
00369       eleTag,
00370       "#DOF does not match with number at nodes");
00371    theElements->removeComponent(eleTag);
00372    return false;
00373       }
00374 #endif      
00375 
00376       // mark the Domain as having been changed
00377       this->domainChange();
00378   } else 
00379       g3ErrorHandler->warning("Domain::addElement - element %d %s\n",
00380          eleTag,
00381          "could not be added to container");      
00382 
00383   return result;
00384 }
00385 
00386 
00387 
00388 // void addNode(Node *);
00389 // Method to add a Node to the model.
00390 
00391 bool
00392 Domain::addNode(Node * node)
00393 {
00394   int nodTag = node->getTag();
00395 
00396   TaggedObject *other = theNodes->getComponentPtr(nodTag);
00397   if (other != 0) {
00398       g3ErrorHandler->warning("Domain::addNode - node with tag %d %s\n",
00399          nodTag,
00400          "already exists in model");       
00401       return false;
00402   }
00403   
00404   bool result = theNodes->addComponent(node);
00405   if (result == true) {
00406       node->setDomain(this);
00407       this->domainChange();
00408       
00409       // see if the physical bounds are changed
00410       // note this assumes 0,0,0,0,0,0 as startup min,max values
00411       const Vector &crds = node->getCrds();
00412       int dim = crds.Size();
00413       if (dim >= 1) {
00414    double x = crds(0);
00415    if (x < theBounds(0)) theBounds(0) = x;
00416    if (x > theBounds(3)) theBounds(3) = x;
00417       } 
00418       if (dim >= 2) {
00419    double y = crds(1);
00420    if (y < theBounds(1)) theBounds(1) = y;
00421    if (y > theBounds(4)) theBounds(4) = y;   
00422       } 
00423       if (dim == 3) {
00424    double z = crds(2);
00425    if (z < theBounds(2)) theBounds(2) = z;
00426    if (z > theBounds(5)) theBounds(5) = z;   
00427       }
00428       
00429   } else
00430       g3ErrorHandler->warning("Domain::addNode - node with tag %d %s\n",
00431          nodTag,
00432          "could not be added to container");            
00433   return result;
00434 }
00435 
00436 
00437 // void addSP_Constraint(SP_Constraint *);
00438 // Method to add a constraint to the model.
00439 //
00440 
00441 bool
00442 Domain::addSP_Constraint(SP_Constraint *spConstraint)
00443 {
00444 #ifdef _G3DEBUG    
00445     // check the Node exists in the Domain
00446     int nodeTag = spConstraint->getNodeTag();
00447     Node *nodePtr = this->getNode(nodeTag);
00448     if (nodePtr == 0) {
00449  g3ErrorHandler->warning("Domain::addSP_Constraint - %s %d %s\n",
00450                                 "cannot add as node node with tag",
00451     nodeTag,
00452     "does not exist in model");        
00453  return false;
00454     }
00455 
00456     // check that the DOF specified exists at the Node
00457     int numDOF = nodePtr->getNumberDOF();
00458     if (numDOF < spConstraint->getDOF_Number()) {
00459  g3ErrorHandler->warning("Domain::addSP_Constraint - %s %d %s\n",
00460                                 "cannot add as node node with tag",
00461     nodeTag,
00462     "does not have associated constrained DOF"); 
00463  return false;
00464     }      
00465 #endif
00466 
00467   // check that no other object with similar tag exists in model
00468   int tag = spConstraint->getTag();
00469   TaggedObject *other = theSPs->getComponentPtr(tag);
00470   if (other != 0) {
00471       g3ErrorHandler->warning("Domain::addSP_Constraint - %s %d %s\n",
00472          "cannot add as constraint with tag",
00473          tag,
00474          "already exists in model");             
00475       return false;
00476   }
00477   
00478   bool result = theSPs->addComponent(spConstraint);
00479   if (result == false) {
00480       g3ErrorHandler->warning("Domain::addSP_Constraint - %s %d %s\n",
00481          "cannot add constraint with tag",
00482          tag,
00483          "to the container");             
00484       return false;
00485   } 
00486 
00487   spConstraint->setDomain(this);
00488   this->domainChange();  
00489 
00490   return true;
00491 }
00492 
00493 
00494 // void addMP_Constraint(MP_Constraint *);
00495 // Method to add a constraint to the model.
00496 //
00497 
00498 bool
00499 Domain::addMP_Constraint(MP_Constraint *mpConstraint)
00500 {
00501 #ifdef _G3DEBUG
00502     // perform the checks
00503     int nodeConstrained = mpConstraint->getNodeConstrained();
00504     Node *nodePtr = this->getNode(nodeConstrained);
00505     if (nodePtr == 0) {
00506  g3ErrorHandler->warning("Domain::addMP_Constraint - %s %d %s\n",
00507                                 "cannot add as constrained node with tag",
00508     nodeConstrained,
00509     "does not exist in model");         
00510  return false;
00511     }
00512     
00513     int nodeRetained = mpConstraint->getNodeRetained();      
00514     nodePtr = this->getNode(nodeRetained);
00515     if (nodePtr == 0) {
00516  g3ErrorHandler->warning("Domain::addMP_Constraint - %s %d %s\n",
00517                                 "cannot add as retained node with tag",
00518     nodeRetained,
00519     "does not exist in model");  
00520  return false;
00521     }      
00522     // MISSING CODE
00523 #endif
00524 
00525   // check that no other object with similar tag exists in model
00526   int tag = mpConstraint->getTag();
00527   TaggedObject *other = theMPs->getComponentPtr(tag);
00528   if (other != 0) {
00529       g3ErrorHandler->warning("Domain::addMP_Constraint - %s %d %s\n",
00530          "cannot add as constraint with tag",
00531          tag,
00532          "already exists in model");             
00533       return false;
00534   }
00535   
00536   bool result = theMPs->addComponent(mpConstraint);
00537   if (result == true) {
00538       mpConstraint->setDomain(this);
00539       this->domainChange();
00540   } else
00541       g3ErrorHandler->warning("Domain::addMP_Constraint - %s %d %s\n",
00542          "cannot add constraint with tag",
00543          tag,
00544          "to the container");                   
00545   return result;
00546 }
00547 
00548 bool 
00549 Domain::addLoadPattern(LoadPattern *load)
00550 {
00551     // first check if a load pattern with a similar tag exists in model
00552     int tag = load->getTag();
00553     TaggedObject *other = theLoadPatterns->getComponentPtr(tag);
00554     if (other != 0) {
00555  g3ErrorHandler->warning("Domain::addLoadPattern - %s %d %s\n",
00556     "cannot add as LoadPattern with tag",
00557     tag,
00558     "already exists in model");             
00559  return false;
00560     }    
00561 
00562     // now we add the load pattern to the container for load pattrens
00563     bool result = theLoadPatterns->addComponent(load);
00564     if (result == true) {
00565  load->setDomain(this);
00566  this->domainChange();
00567     }
00568     else 
00569       g3ErrorHandler->warning("Domain::addLoadPattern - %s %d %s\n",
00570          "cannot add LoadPattern with tag",
00571          tag,
00572          "to the container");                    
00573     return result;
00574 }    
00575 
00576 
00577 bool
00578 Domain::addSP_Constraint(SP_Constraint *spConstraint, int pattern)
00579 {
00580 #ifdef _G3DEBUG
00581     // check the Node exists in the Domain
00582     int nodeTag = spConstraint->getNodeTag();
00583     Node *nodePtr = this->getNode(nodeTag);
00584     if (nodePtr == 0) {
00585  g3ErrorHandler->warning("Domain::addSP_Constraint - %s %d %s\n",
00586                                 "cannot add as node node with tag",
00587     nodeTag,
00588     "does not exist in model");        
00589  return false;
00590     }
00591 
00592     // check that the DOF specified exists at the Node
00593     int numDOF = nodePtr->getNumberDOF();
00594     if (numDOF < spConstraint->getDOF_Number()) {
00595  g3ErrorHandler->warning("Domain::addSP_Constraint - %s %d %s\n",
00596                                 "cannot add as node node with tag",
00597     nodeTag,
00598     "does not have associated constrained DOF"); 
00599  return false;
00600     }      
00601 #endif
00602 
00603   // now add it to the pattern
00604   TaggedObject *thePattern = theLoadPatterns->getComponentPtr(pattern);
00605   if (thePattern == 0) {
00606       g3ErrorHandler->warning("Domain::addSP_Constraint - %s %d %s\n",
00607          "cannot add as pattern with tag",
00608          pattern,
00609          "does not exist in domain"); 
00610       return false;
00611   }
00612   LoadPattern *theLoadPattern = (LoadPattern *)thePattern;
00613   bool result = theLoadPattern->addSP_Constraint(spConstraint);
00614   if (result == false) {
00615       g3ErrorHandler->warning("Domain::addSP_Constraint - %d %s\n",
00616          pattern,
00617          "pattern could not add the SP_Constraint"); 
00618     return false;
00619   }
00620 
00621   spConstraint->setDomain(this);
00622   this->domainChange();  
00623 
00624   return true;
00625 }
00626 
00627 bool 
00628 Domain::addNodalLoad(NodalLoad *load, int pattern)
00629 {
00630 #ifdef _G3DEBUG
00631     int nodTag = load->getNodeTag();
00632     Node *res = this->getNode(nodTag);
00633     if (res == 0) {
00634  g3ErrorHandler->warning("Domain::addNodalLoad() - no node with tag %d %s\n",
00635     nodTag,
00636     "in  the model, not adding the nodal load");
00637  return false;
00638     }
00639 #endif
00640 
00641     // now add it to the pattern
00642     TaggedObject *thePattern = theLoadPatterns->getComponentPtr(pattern);
00643     if (thePattern == 0) {
00644  g3ErrorHandler->warning("Domain::addNodalLoad() - %s %d %s\n",
00645     "no pattern with tag",
00646     pattern,
00647     "in  the model, not adding the nodal load"); 
00648  return false;
00649     }
00650     LoadPattern *theLoadPattern = (LoadPattern *)thePattern;
00651     bool result = theLoadPattern->addNodalLoad(load);
00652     if (result == false) {
00653  g3ErrorHandler->warning("Domain::addNodalLoad() - %s %d %s\n",
00654     "pattern with tag ",
00655     pattern,
00656     "could not add the load"); 
00657       return false;
00658     }
00659 
00660     load->setDomain(this);    
00661     this->domainChange();
00662 
00663     return result;
00664 }    
00665 
00666 
00667 bool 
00668 Domain::addElementalLoad(ElementalLoad *load, int pattern)
00669 {
00670 #ifdef _G3DEBUG
00671     int eleTag = load->getElementTag();
00672     Element *res = this->getElement(eleTag);
00673     if (res == 0) { 
00674  g3ErrorHandler->warning("Domain::addElementalLoad() - %s %d %s\n",
00675     "no element with tag",
00676     eleTag,
00677     "in  the model, not adding the nodal load"); 
00678  return false;
00679     }
00680 #endif
00681 
00682     // now add it to the pattern
00683     TaggedObject *thePattern = theLoadPatterns->getComponentPtr(pattern);
00684     if (thePattern == 0) {
00685  g3ErrorHandler->warning("Domain::addElementalLoad() - %s %d %s\n",
00686     "no pattern with tag",
00687     pattern,
00688     "in  the model, not adding the nodal load");
00689  return false;
00690     }
00691     LoadPattern *theLoadPattern = (LoadPattern *)thePattern;
00692     bool result = theLoadPattern->addElementalLoad(load);
00693     if (result == false) {
00694  g3ErrorHandler->warning("Domain::addElementalLoad() - %s %d %s\n",
00695     "pattern with tag ",
00696     pattern,
00697     "could not add the load"); 
00698  return false;
00699     }
00700 
00701 
00702     load->setDomain(this);
00703     this->domainChange();
00704     return result;
00705 }
00706 
00707 
00708 /* GENERAL NOTE ON REMOVAL OF COMPONENTS:
00709 **   downward casts (while bad) are o.k. as only the type
00710 **   of components can be added to the storage objects, e.g.
00711 **   only elements can be added to theElements therefore
00712 **   casting a DomainComponent from theElements to an Element is o.k.
00713 */
00714 
00715 void
00716 Domain::clearAll(void) {
00717     // clear the loads and constraints from any load pattern
00718     LoadPatternIter &thePatterns = this->getLoadPatterns();
00719     LoadPattern *thePattern;
00720     while ((thePattern = thePatterns()) != 0)
00721  thePattern->clearAll();
00722 
00723     // clean out the containers
00724     theElements->clearAll();
00725     theNodes->clearAll();
00726     theSPs->clearAll();
00727     theMPs->clearAll();
00728     theLoadPatterns->clearAll();
00729 
00730     // remove the recorders
00731     for (int i=0; i<numRecorders; i++)
00732  delete theRecorders[i];
00733     numRecorders = 0;
00734     
00735     if (theRecorders != 0) {
00736  free((void *)theRecorders);    
00737  theRecorders = 0;
00738     }
00739 
00740     // set the time back to 0.0
00741     currentTime = 0.0;
00742     committedTime = 0.0;
00743 
00744     // set the bounds around the origin
00745     theBounds(0) = 0;
00746     theBounds(1) = 0;
00747     theBounds(2) = 0;
00748     theBounds(3) = 0;
00749     theBounds(4) = 0;    
00750     theBounds(5) = 0;        
00751 
00752     // mark the domain as having changed
00753     this->domainChange();
00754 }
00755 
00756 
00757 Element *
00758 Domain::removeElement(int tag)
00759 {
00760   // remove the object from the container    
00761   TaggedObject *mc = theElements->removeComponent(tag);
00762   
00763   // if not there return 0
00764   if (mc == 0) 
00765       return 0;
00766 
00767   // otherwise mark the domain as having changed
00768   this->domainChange();
00769   
00770   // perform a downward cast to an Element (safe as only Element added to
00771   // this container, 0 the Elements DomainPtr and return the result of the cast  
00772   Element *result = (Element *)mc;
00773   result->setDomain(0);
00774   return result;
00775 }
00776 
00777 Node *
00778 Domain::removeNode(int tag)
00779 {
00780   // remove the object from the container
00781   TaggedObject *mc = theNodes->removeComponent(tag);
00782   
00783   // if not there return 0
00784   if (mc == 0) 
00785       return 0;  
00786 
00787   // mark the domain has having changed 
00788   this->domainChange();
00789   
00790   // perform a downward cast to a Node (safe as only Node added to
00791   // this container and return the result of the cast
00792   Node *result = (Node *)mc;
00793   result->setDomain(0);
00794   return result;
00795 }
00796 
00797 
00798 SP_Constraint *
00799 Domain::removeSP_Constraint(int tag)
00800 {
00801     // remove the object from the container    
00802     TaggedObject *mc = theSPs->removeComponent(tag);
00803     
00804     // if not there return 0    
00805     if (mc == 0) 
00806  return 0;
00807 
00808     // mark the domain as having changed    
00809     this->domainChange();
00810     
00811     // perform a downward cast, set the objects domain pointer to 0
00812     // and return the result of the cast    
00813     SP_Constraint *result = (SP_Constraint *)mc;
00814     result->setDomain(0);
00815 
00816     // should check that theLoad and result are the same    
00817     return result;
00818 }
00819 
00820 MP_Constraint *
00821 Domain::removeMP_Constraint(int tag)
00822 {
00823     // remove the object from the container        
00824     TaggedObject *mc = theMPs->removeComponent(tag);
00825     
00826     // if not there return 0    
00827     if (mc == 0) 
00828  return 0;
00829 
00830     // mark the domain as having changed    
00831     this->domainChange();
00832     
00833     // perform a downward cast, set the objects domain pointer to 0
00834     // and return the result of the cast        
00835     MP_Constraint *result = (MP_Constraint *)mc;
00836     result->setDomain(0);
00837     return result;
00838 }    
00839 
00840 LoadPattern *
00841 Domain::removeLoadPattern(int tag)
00842 {
00843     // remove the object from the container            
00844     TaggedObject *obj = theLoadPatterns->removeComponent(tag);
00845     
00846     // if not there return 0    
00847     if (obj == 0)
00848  return 0;
00849     
00850     // perform a downward cast, set the objects domain pointer to 0
00851     // and return the result of the cast            
00852     LoadPattern *result = (LoadPattern *)obj;
00853     result->setDomain(0);
00854 
00855     //
00856     // now set the Domain pointer for all loads and SP constraints 
00857     // in the loadPattern to be 0
00858     //
00859     
00860     NodalLoad *theNodalLoad;
00861     NodalLoadIter &theNodalLoads = result->getNodalLoads();
00862     while ((theNodalLoad = theNodalLoads()) != 0) {
00863       theNodalLoad->setDomain(0);
00864     }
00865 
00866     ElementalLoad *theElementalLoad;
00867     ElementalLoadIter &theElementalLoads = result->getElementalLoads();
00868     while ((theElementalLoad = theElementalLoads()) != 0) {
00869       theElementalLoad->setDomain(0);
00870     }
00871 
00872     int numSPs = 0;
00873     SP_Constraint *theSP_Constraint;
00874     SP_ConstraintIter &theSP_Constraints = result->getSPs();
00875     while ((theSP_Constraint = theSP_Constraints()) != 0) {
00876  numSPs++;
00877  theSP_Constraint->setDomain(0);
00878     }
00879 
00880     // mark the domain has having changed if numSPs > 0
00881     // as the constraint handlers have to be redone
00882     if (numSPs > 0)
00883  this->domainChange();
00884 
00885     // finally return the load pattern
00886     return result;    
00887 }    
00888 
00889 
00890 
00891 
00892 
00893 NodalLoad *
00894 Domain::removeNodalLoad(int tag, int loadPattern)
00895 {
00896   // remove the object from the container            
00897   LoadPattern *theLoadPattern = this->getLoadPattern(loadPattern);
00898     
00899   // if not there return 0    
00900   if (theLoadPattern == 0)
00901     return 0;
00902     
00903   return theLoadPattern->removeNodalLoad(tag);
00904 }    
00905 
00906 
00907 ElementalLoad *
00908 Domain::removeElementalLoad(int tag, int loadPattern)
00909 {
00910   // remove the object from the container            
00911   LoadPattern *theLoadPattern = this->getLoadPattern(loadPattern);
00912     
00913   // if not there return 0    
00914   if (theLoadPattern == 0)
00915     return 0;
00916     
00917   return theLoadPattern->removeElementalLoad(tag);
00918 }    
00919 
00920 
00921 SP_Constraint *
00922 Domain::removeSP_Constraint(int tag, int loadPattern)
00923 {
00924   // remove the object from the container            
00925   LoadPattern *theLoadPattern = this->getLoadPattern(loadPattern);
00926     
00927   // if not there return 0    
00928   if (theLoadPattern == 0)
00929     return 0;
00930     
00931   SP_Constraint *theSP = theLoadPattern->removeSP_Constraint(tag);
00932   if (theSP != 0)
00933     this->domainChange();
00934 
00935   return theSP;
00936 }    
00937 
00938 ElementIter &
00939 Domain::getElements()
00940 {
00941     theEleIter->reset();    
00942     return *theEleIter;
00943 }
00944 
00945 
00946 NodeIter &
00947 Domain::getNodes()
00948 {
00949     theNodIter->reset();    
00950     return *theNodIter;
00951 }
00952 
00953 SP_ConstraintIter &
00954 Domain::getSPs()
00955 {
00956     theSP_Iter->reset();
00957     return *theSP_Iter;;
00958 }
00959 
00960 SP_ConstraintIter &
00961 Domain::getDomainAndLoadPatternSPs()
00962 {
00963     allSP_Iter->reset();
00964     return *allSP_Iter;;
00965 }
00966 
00967 
00968 MP_ConstraintIter &
00969 Domain::getMPs()
00970 {
00971     theMP_Iter->reset();
00972     return *theMP_Iter;;
00973 }
00974 
00975 
00976 LoadPatternIter &
00977 Domain::getLoadPatterns()
00978 {
00979     theLoadPatternIter->reset();
00980     return *theLoadPatternIter;;
00981 }
00982 
00983 /* GENERAL NOTE ON RETRIEVAL OF COMPONENT PTRs:
00984 **   downward casts (while bad) are o.k. as only the type
00985 **   of components can be added to the storage objects, e.g.
00986 **   only elements can be added to theElements
00987 */
00988 
00989 Element *
00990 Domain::getElement(int tag) 
00991 {
00992   TaggedObject *mc = theElements->getComponentPtr(tag);
00993   
00994   // if not there return 0 otherwise perform a cast and return that
00995   if (mc == 0) 
00996       return 0;
00997   Element *result = (Element *)mc;
00998   return result;
00999 }
01000 
01001 
01002 Node *
01003 Domain::getNode(int tag) 
01004 {
01005   TaggedObject *mc = theNodes->getComponentPtr(tag);
01006 
01007   // if not there return 0 otherwise perform a cast and return that  
01008   if (mc == 0) 
01009       return 0;  
01010   Node *result = (Node *)mc;
01011   return result;
01012 }
01013 
01014 SP_Constraint *
01015 Domain::getSP_Constraint(int tag) 
01016 {
01017   TaggedObject *mc = theSPs->getComponentPtr(tag);
01018 
01019   // if not there return 0 otherwise perform a cast and return that  
01020   if (mc == 0) 
01021       return 0;
01022   SP_Constraint *result = (SP_Constraint *)mc;
01023   return result;
01024 }
01025 
01026 MP_Constraint *
01027 Domain::getMP_Constraint(int tag) 
01028 {
01029   TaggedObject *mc = theMPs->getComponentPtr(tag);
01030 
01031   // if not there return 0 otherwise perform a cast and return that
01032   if (mc == 0) 
01033       return 0;
01034   MP_Constraint *result = (MP_Constraint *)mc;
01035   return result;
01036 }
01037 
01038 LoadPattern *
01039 Domain::getLoadPattern(int tag) 
01040 {
01041   TaggedObject *mc = theLoadPatterns->getComponentPtr(tag);
01042   // if not there return 0 otherwise perform a cast and return that  
01043   if (mc == 0) 
01044       return 0;
01045   LoadPattern *result = (LoadPattern *)mc;
01046   return result;
01047 }
01048 
01049 
01050 double
01051 Domain::getCurrentTime(void) const
01052 {
01053     return currentTime;
01054 }
01055 
01056 
01057 int 
01058 Domain::getNumElements(void) const
01059 {
01060     return theElements->getNumComponents();
01061 }
01062 int 
01063 Domain::getNumNodes(void) const
01064 {
01065     return theNodes->getNumComponents();
01066 }
01067 
01068 int 
01069 Domain::getNumSPs(void) const
01070 {
01071     return theSPs->getNumComponents();
01072 }
01073 
01074 
01075 int 
01076 Domain::getNumMPs(void) const
01077 {
01078     return theMPs->getNumComponents();
01079 }
01080 
01081 int 
01082 Domain::getNumLoadPatterns(void) const
01083 {
01084     return theLoadPatterns->getNumComponents();
01085 }
01086 
01087 
01088 const Vector &
01089 Domain::getPhysicalBounds(void)
01090 {
01091     return theBounds;
01092 }
01093 
01094 
01095 
01096 Graph  &
01097 Domain::getElementGraph(void)
01098 {
01099     if (eleGraphBuiltFlag == false) {
01100  // if the current graph is out of date .. delete it so we can start again
01101  if (theElementGraph != 0) {
01102      delete theElementGraph;
01103      theElementGraph = 0;
01104  } 
01105  // create an empty graph 
01106         theElementGraph = new Graph(this->getNumElements()+START_VERTEX_NUM);
01107 
01108  if (theElementGraph == 0) {// if still 0 try a smaller one
01109      theElementGraph = new Graph();
01110      
01111      if (theElementGraph == 0) // if still 0 out of memory
01112   g3ErrorHandler->fatal("Domain::getElementGraph() - out of memory\n");
01113  }
01114 
01115  // now build the graph
01116  if (this->buildEleGraph(theElementGraph) == 0)
01117      eleGraphBuiltFlag = true;
01118  else
01119      g3ErrorHandler->warning("Domain::getElementGraph() - %s\n",
01120         "failed to build the element graph");     
01121     }
01122     
01123     // return the Graph
01124     return *theElementGraph;
01125 }
01126 
01127 
01128 
01129 Graph  &
01130 Domain::getNodeGraph(void)
01131 {
01132     if (nodeGraphBuiltFlag == false) {
01133  
01134  // if the current graph is out of date .. delete it so we can start again
01135  if (theNodeGraph != 0) {
01136      delete theNodeGraph;
01137      theNodeGraph = 0;
01138  }
01139 
01140  // try to get a graph as big as we should need
01141  theNodeGraph = new Graph(this->getNumNodes()+START_VERTEX_NUM);
01142  
01143  if (theNodeGraph == 0) { // if still 0 try a smaller one
01144      theNodeGraph = new Graph();
01145 
01146      if (theNodeGraph == 0) // if still 0 out of memory
01147   g3ErrorHandler->fatal("Domain::getNodeGraph() - out of memory\n");
01148  }
01149  
01150  // now build the graph
01151  if (this->buildNodeGraph(theNodeGraph) == 0)
01152      nodeGraphBuiltFlag = true;
01153  else
01154      g3ErrorHandler->warning("Domain::getNodeGraph() - %s\n",
01155         "failed to build the node graph");
01156     }
01157 
01158     // return the Graph
01159     return *theNodeGraph;
01160 }
01161 
01162 
01163 void
01164 Domain::setCommitTag(int newTag)
01165 {
01166     commitTag = newTag;
01167 }
01168 
01169 void
01170 Domain::setCurrentTime(double newTime)
01171 {
01172     currentTime = newTime;
01173 }
01174 
01175 void
01176 Domain::setCommittedTime(double newTime)
01177 {
01178     committedTime = newTime;
01179 }
01180 
01181 
01182 void
01183 Domain::applyLoad(double timeStep)
01184 {
01185     //
01186     // first loop over nodes and elements getting them to first zero their loads
01187     //
01188 
01189     Node *nodePtr;
01190     NodeIter &theNodeIter = this->getNodes();
01191     while ((nodePtr = theNodeIter()) != 0)
01192  nodePtr->zeroUnbalancedLoad();
01193 
01194     Element *elePtr;
01195     ElementIter &theElemIter = this->getElements();    
01196     while ((elePtr = theElemIter()) != 0)
01197  if (elePtr->isSubdomain() == false)
01198      elePtr->zeroLoad();    
01199 
01200     // now loop over load patterns, invoking applyLoad on them
01201     LoadPattern *thePattern;
01202     LoadPatternIter &thePatterns = this->getLoadPatterns();
01203     while((thePattern = thePatterns()) != 0)
01204       thePattern->applyLoad(timeStep);
01205 
01206     //
01207     // finally loop over the MP_Constraints and SP_Constraints of the domain
01208     //
01209     
01210     MP_ConstraintIter &theMPs = this->getMPs();
01211     MP_Constraint *theMP;
01212     while ((theMP = theMPs()) != 0)
01213  theMP->applyConstraint(timeStep);
01214 
01215     SP_ConstraintIter &theSPs = this->getSPs();
01216     SP_Constraint *theSP;
01217     while ((theSP = theSPs()) != 0)
01218  theSP->applyConstraint(timeStep);
01219 
01220     // set the current pseudo time in the domai to be newTime
01221     currentTime = timeStep;
01222 }
01223 
01224 
01225 void
01226 Domain::setLoadConstant(void)
01227 {
01228     // loop over all the load patterns that are currently added to the domain
01229     // getting them to set their loads as now constant
01230     LoadPattern *thePattern;
01231     LoadPatternIter &thePatterns = this->getLoadPatterns();
01232     while((thePattern = thePatterns()) != 0)
01233       thePattern->setLoadConstant();
01234 }
01235 
01236 int
01237 Domain::initialize(void)
01238 {
01239   int result = 0;
01240   Element *elePtr;
01241   ElementIter &theElemIter = this->getElements();    
01242   while ((elePtr = theElemIter()) != 0) {
01243     int res = elePtr->setKi();
01244     if (res != 0)
01245       result = res;
01246   }
01247   return result;
01248 }
01249 
01250 
01251 
01252 int
01253 Domain::commit(void)
01254 {
01255     // 
01256     // first invoke commit on all nodes and elements in the domain
01257     //
01258 
01259     Node *nodePtr;
01260     NodeIter &theNodeIter = this->getNodes();
01261     while ((nodePtr = theNodeIter()) != 0) {
01262       nodePtr->commitState();
01263     }
01264     
01265     Element *elePtr;
01266     ElementIter &theElemIter = this->getElements();    
01267     while ((elePtr = theElemIter()) != 0) {
01268       elePtr->commitState();
01269     }
01270 
01271     // set the new committed time in the domain
01272     committedTime = currentTime;
01273 
01274     // invoke record on all recorders
01275     for (int i=0; i<numRecorders; i++)
01276  theRecorders[i]->record(commitTag);
01277 
01278     // update the commitTag
01279     commitTag++;
01280     return 0;
01281 }
01282 
01283 int
01284 Domain::revertToLastCommit(void)
01285 {
01286     // 
01287     // first invoke revertToLastCommit  on all nodes and elements in the domain
01288     //
01289     
01290     Node *nodePtr;
01291     NodeIter &theNodeIter = this->getNodes();
01292     while ((nodePtr = theNodeIter()) != 0)
01293  nodePtr->revertToLastCommit();
01294     
01295     Element *elePtr;
01296     ElementIter &theElemIter = this->getElements();    
01297     while ((elePtr = theElemIter()) != 0) 
01298  elePtr->revertToLastCommit();
01299 
01300     // set the current time and load factor in the domain to last committed
01301     currentTime = committedTime;
01302 
01303     // apply load for the last committed time
01304     this->applyLoad(currentTime);
01305     
01306     return 0;
01307 }
01308 
01309 int
01310 Domain::revertToStart(void)
01311 {
01312     // 
01313     // first invoke revertToLastCommit  on all nodes and 
01314     // elements in the domain
01315     //
01316     
01317     Node *nodePtr;
01318     NodeIter &theNodeIter = this->getNodes();
01319     while ((nodePtr = theNodeIter()) != 0) 
01320  nodePtr->revertToStart();
01321 
01322     Element *elePtr;
01323     ElementIter &theElements = this->getElements();    
01324     while ((elePtr = theElements()) != 0) 
01325  elePtr->revertToStart();
01326     
01327     // set the current time and load factor in the domain to last committed
01328     committedTime = 0;
01329     currentTime = 0;
01330 
01331     // apply load for the last committed time
01332     this->applyLoad(currentTime);
01333     
01334     return 0;
01335 }
01336 
01337 int
01338 Domain::update(void)
01339 {
01340     // invoke update on all the ele's .. subdomains need this
01341     ElementIter &theEles = this->getElements();
01342     Element *theEle;
01343     while ((theEle = theEles()) != 0)
01344  theEle->update();
01345     
01346     return 0;
01347 }
01348 
01349 int
01350 Domain::setEigenvalues(const Vector &theValues)
01351 {
01352   // make sure the eigen value vector is large enough
01353   if (theEigenvalues == 0 || theEigenvalues->Size() != theValues.Size()) {
01354     
01355     // if not zero delete the old and create a new one
01356     if (theEigenvalues != 0)
01357       delete theEigenvalues;
01358 
01359     // create the new vector
01360     theEigenvalues = new Vector(theValues);
01361   } else
01362 
01363     // otherwise just a straight assignment
01364     *theEigenvalues = theValues;
01365 
01366 
01367   // now set the time at which eigen values were determined to be current domain time
01368   theEigenvalueSetTime = this->getCurrentTime();
01369 
01370   return 0;
01371 }
01372 
01373 
01374 const Vector &
01375 Domain::getEigenvalues(void) 
01376 {
01377   // ensure the eigen values were set
01378   if (theEigenvalues == 0) {
01379     g3ErrorHandler->fatal("Domain::getEigenvalues - Eigenvalues were never set\n");
01380   }
01381 
01382   return *theEigenvalues;
01383 }  
01384 
01385 double 
01386 Domain::getTimeEigenvaluesSet(void) 
01387 {
01388   return theEigenvalueSetTime;
01389 }
01390 
01391 void
01392 Domain::setDomainChangeStamp(int newStamp)
01393 {
01394     currentGeoTag = newStamp;
01395 }
01396 
01397 
01398 
01399 int
01400 Domain::hasDomainChanged(void)
01401 { 
01402     // if the flag indicating the domain has changed since the
01403     // last call to this method has changed, increment the integer
01404     // and reset the flag
01405     bool result = hasDomainChangedFlag;
01406     hasDomainChangedFlag = false;
01407     if (result == true) {
01408  currentGeoTag++;
01409  nodeGraphBuiltFlag = false;
01410  eleGraphBuiltFlag = false;
01411     }
01412 
01413     // return the integer so user can determine if domain has changed 
01414     // since their last call to this method
01415     return currentGeoTag;
01416 }
01417 
01418 
01419 void
01420 Domain::Print(ostream &s, int flag) 
01421 {
01422 
01423   s << "Current Domain Information\n";
01424   s << "\tCurrent Time: " << currentTime;
01425   s << "\ntCommitted Time: " << committedTime << endl;
01426 
01427   s << "\nNODE DATA: NumNodes: " << theNodes->getNumComponents() << "\n";
01428   theNodes->Print(s, flag);
01429 
01430   s << "\nELEMENT DATA: NumEle: " << theElements->getNumComponents() << "\n";
01431   theElements->Print(s, flag);
01432   
01433   s << "\nSP_Constraints: numConstraints: ";
01434   s << theSPs->getNumComponents() << "\n";
01435   theSPs->Print(s, flag);
01436   
01437   s << "\nMP_Constraints: numConstraints: ";
01438   s << theMPs->getNumComponents() << "\n";
01439   theMPs->Print(s, flag);
01440 
01441   s << "\nLOAD PATTERNS: num Patterns: ";
01442   s << theLoadPatterns->getNumComponents() << "\n\n";
01443   theLoadPatterns->Print(s, flag);
01444 }
01445 
01446 ostream &operator<<(ostream &s, Domain &M)
01447 {
01448   M.Print(s);
01449   return s;
01450 }
01451 
01452 
01453 int  
01454 Domain::addRecorder(Recorder &theRecorder)
01455 {
01456     Recorder **newRecorders = (Recorder **)malloc((numRecorders+1)*sizeof(Recorder *)); 
01457     if (newRecorders == 0) {
01458  g3ErrorHandler->warning("Domain::addRecorder() - %s\n",
01459     "could not add ran out of memory\n");
01460  return -1;
01461     }
01462     
01463     for (int i=0; i<numRecorders; i++)
01464  newRecorders[i] = theRecorders[i];
01465     newRecorders[numRecorders] = &theRecorder;
01466 
01467     if (theRecorders != 0)
01468  free((void *)theRecorders);
01469     
01470     theRecorders = newRecorders;
01471     numRecorders++;
01472     return 0;
01473 }
01474 
01475 
01476 
01477 int
01478 Domain::removeRecorders(void)
01479 {
01480     for (int i=0; i<numRecorders; i++)  
01481       delete theRecorders[i];
01482     
01483     if (theRecorders != 0) {
01484  free((void *)theRecorders);
01485  theRecorders = 0;
01486     }
01487   
01488     theRecorders = 0;
01489     numRecorders = 0;
01490     return 0;
01491 }
01492 
01493 
01494 int  
01495 Domain::playback(int cTag)
01496 {
01497     for (int i=0; i<numRecorders; i++)
01498  theRecorders[i]->playback(cTag);
01499     return 0;
01500 }
01501 
01502 
01503 void
01504 Domain::domainChange(void)
01505 {
01506     hasDomainChangedFlag = true;
01507 }
01508 
01509 int 
01510 Domain::buildEleGraph(Graph *theEleGraph)
01511 {
01512     int numVertex = this->getNumElements();
01513 
01514     // see if quick return
01515 
01516     if (numVertex == 0) 
01517  return 0;
01518 
01519     
01520     // create another vertices array which aids in adding edges
01521     
01522     int *theElementTagVertices = 0;
01523     int maxEleNum = 0;
01524     Element *elePtr;
01525     ElementIter &eleIter = this->getElements();
01526     while ((elePtr = eleIter()) != 0)
01527  if (elePtr->getTag() > maxEleNum)
01528      maxEleNum = elePtr->getTag();
01529 
01530     theElementTagVertices = new int[maxEleNum+1];
01531 
01532     if (theElementTagVertices == 0) {
01533  cerr << "WARNING Domain::buildEleGraph ";
01534  cerr << " - Not Enough Memory for ElementTagVertices\n";
01535  return -1;
01536     }
01537 
01538     for (int j=0; j<=maxEleNum; j++) theElementTagVertices[j] = -1;
01539 cerr << "Domain::buildEleGraph numVertex maxEleNum " << numVertex << " " << maxEleNum << endl;
01540     // now create the vertices with a reference equal to the element number.
01541     // and a tag which ranges from 0 through numVertex-1
01542 
01543     ElementIter &eleIter2 = this->getElements();
01544     int count = START_VERTEX_NUM;
01545     while ((elePtr = eleIter2()) != 0) {
01546  int ElementTag = elePtr->getTag();
01547  Vertex *vertexPtr = new Vertex(count,ElementTag);
01548 
01549  if (vertexPtr == 0) {
01550      cerr << "WARNING Domain::buildEleGraph";
01551      cerr << " - Not Enough Memory to create ";
01552      cerr << count << "th Vertex\n";
01553      delete [] theElementTagVertices;
01554      return -1;
01555  }
01556 
01557  theEleGraph->addVertex(vertexPtr);
01558  theElementTagVertices[ElementTag] = count++;
01559  
01560     }
01561 
01562     // We now need to determine which elements are asssociated with each node.
01563     // As this info is not in the Node interface we must build it; which we
01564     // do using vertices for each node, when we addVertex at thes nodes we
01565     // will not be adding vertices but element tags.
01566 
01567     Vertex **theNodeTagVertices = 0;
01568     int maxNodNum = 0;
01569     Node *nodPtr;
01570     NodeIter &nodeIter = this->getNodes();
01571     while ((nodPtr = nodeIter()) != 0)
01572  if (nodPtr->getTag() > maxNodNum)
01573      maxNodNum = nodPtr->getTag();
01574 
01575     theNodeTagVertices = new Vertex *[maxNodNum+1];
01576 
01577     if (theNodeTagVertices == 0) {
01578  cerr << "WARNING Domain::buildEleGraph ";
01579  cerr << " - Not Enough Memory for NodeTagVertices\n";
01580  return -1;
01581     }
01582     
01583     for (int l=0; l<=maxNodNum; l++) theNodeTagVertices[l] = 0;
01584 
01585     // now create the vertices with a reference equal to the node number.
01586     // and a tag which ranges from 0 through numVertex-1 and placed in
01587     // theNodeTagVertices at a position equal to the node's tag.
01588 
01589     NodeIter &nodeIter2 = this->getNodes();
01590     count = START_VERTEX_NUM;
01591     while ((nodPtr = nodeIter2()) != 0) {
01592  int nodeTag = nodPtr->getTag();
01593  Vertex *vertexPtr = new Vertex(count++,nodeTag);
01594  theNodeTagVertices[nodeTag] = vertexPtr;
01595 
01596  if (vertexPtr == 0) {
01597      cerr << "WARNING Domain::buildEleGraph";
01598      cerr << " - Not Enough Memory to create ";
01599      cerr << count << "th Node Vertex\n";
01600      delete [] theNodeTagVertices;
01601      return -1;
01602  }
01603     }
01604 
01605     // now add the the Elements to the nodes
01606 
01607     ElementIter &eleIter3 = this->getElements();
01608 
01609     while((elePtr = eleIter3()) != 0) {
01610  int eleTag = elePtr->getTag();
01611  const ID &id = elePtr->getExternalNodes();
01612 
01613  int size = id.Size();
01614  for (int i=0; i<size; i++) 
01615      theNodeTagVertices[id(i)]->addEdge(eleTag);
01616     }
01617 
01618 
01619 
01620     // now add the edges to the vertices of our element graph;
01621     // this is done by looping over the Node vertices, getting their 
01622     // Adjacenecy and adding edges between elements with common nodes
01623 
01624 
01625     Vertex *vertexPtr;
01626     for (int k=0; k<=maxNodNum; k++)
01627  if ((vertexPtr = theNodeTagVertices[k]) != 0) {
01628 
01629      const ID &id = vertexPtr->getAdjacency();
01630 
01631      int size = id.Size();
01632      for (int i=0; i<size; i++) {
01633   int Element1 = id(i);
01634 
01635   int vertexTag1 = theElementTagVertices[Element1];
01636 
01637   for (int j=0; j<size; j++) 
01638       if (i != j) {
01639 
01640    int Element2 = id(j);
01641    int vertexTag2 = theElementTagVertices[Element2];
01642 
01643    // addEdge() adds for both vertices - do only once
01644 
01645 
01646    if (vertexTag1 > vertexTag2) 
01647        theEleGraph->addEdge(vertexTag1,vertexTag2);
01648        theEleGraph->addEdge(vertexTag2,vertexTag1);   
01649       }
01650      }
01651  }
01652 
01653     // done now delete theElementTagVertices, the node Vertices and
01654     // theNodeTagVertices
01655    
01656     delete [] theElementTagVertices;    
01657     
01658     for (int i=0; i<=maxNodNum; i++)
01659  if ((vertexPtr = theNodeTagVertices[i]) != 0) 
01660      delete vertexPtr;
01661      
01662     delete [] theNodeTagVertices;
01663     
01664     return 0;
01665     
01666 }
01667 
01668 int 
01669 Domain::buildNodeGraph(Graph *theNodeGraph)
01670 {
01671     int numVertex = this->getNumNodes();
01672 
01673     if (numVertex == 0) {
01674  return 0;
01675     } 
01676  
01677     // create another vertices array which aids in adding edges
01678     
01679     int *theNodeTagVertices = 0;
01680     int maxNodNum = 0;
01681     Node *nodPtr;
01682     NodeIter &nodeIter = this->getNodes();
01683     while ((nodPtr = nodeIter()) != 0)
01684  if (nodPtr->getTag() > maxNodNum)
01685      maxNodNum = nodPtr->getTag();
01686 
01687     theNodeTagVertices = new int [maxNodNum+1];
01688 
01689     if (theNodeTagVertices == 0) {
01690  cerr << "WARNING Domain::buildNodeGraph ";
01691  cerr << " - Not Enough Memory for NodeTagVertices\n";
01692  return -1;
01693     }
01694     
01695     for (int j=0; j<=maxNodNum; j++) theNodeTagVertices[j] = -1;
01696 
01697     // now create the vertices with a reference equal to the node number.
01698     // and a tag which ranges from START_VERTEX_NUM through 
01699     // numNodes+START_VERTEX_NUM
01700 
01701     NodeIter &nodeIter2 = this->getNodes();
01702     int count = START_VERTEX_NUM;
01703     while ((nodPtr = nodeIter2()) != 0) {
01704  int nodeTag = nodPtr->getTag();
01705  Vertex *vertexPtr = new Vertex(count,nodeTag);
01706 
01707  if (vertexPtr == 0) {
01708      cerr << "WARNING Domain::buildNodeGraph";
01709      cerr << " - Not Enough Memory to create ";
01710      cerr << count << "th Vertex\n";
01711      delete [] theNodeTagVertices;
01712      return -1;
01713  }
01714 
01715  // add the vertex to the graph
01716  theNodeGraph->addVertex(vertexPtr);
01717  theNodeTagVertices[nodeTag] = count++;
01718     }
01719 
01720     // now add the edges, by looping over the Elements, getting their
01721     // IDs and adding edges between all elements who share a node.
01722     
01723     Element *elePtr;
01724     ElementIter &eleIter = this->getElements();
01725 
01726     while((elePtr = eleIter()) != 0) {
01727  const ID &id = elePtr->getExternalNodes();
01728 
01729  int size = id.Size();
01730  for (int i=0; i<size; i++) {
01731      int node1 = id(i);
01732      int vertexTag1 = theNodeTagVertices[node1];
01733      
01734      for (int j=0; j<size; j++) 
01735   if (i != j) {
01736 
01737       int node2 = id(j);
01738       int vertexTag2 = theNodeTagVertices[node2];
01739       
01740       // addEdge() adds for both vertices - do only once
01741       if (vertexTag1 > vertexTag2) 
01742    theNodeGraph->addEdge(vertexTag1,vertexTag2);
01743   }
01744  }
01745     }
01746 
01747     // done now delete theNodeTagVertices
01748     delete [] theNodeTagVertices;
01749     
01750     return 0;
01751 }
01752 
01753 
01754 int 
01755 Domain::sendSelf(int cTag, Channel &theChannel)
01756 {
01757   // update the commitTag and currentGeoTag
01758   commitTag = cTag;
01759   this->hasDomainChanged();
01760 
01761   // first we send info about the current domain flag and the number of
01762   // elements, nodes, constraints and load patterns currently in the domain
01763   int numEle, numNod, numSPs, numMPs, numLPs;
01764   ID domainData(11);
01765   domainData(0) = currentGeoTag;
01766   domainData(1) = numNod = theNodes->getNumComponents();
01767   domainData(2) = numEle = theElements->getNumComponents();
01768   domainData(3) = numSPs = theSPs->getNumComponents();
01769   domainData(4) = numMPs = theMPs->getNumComponents();
01770   domainData(5) = numLPs = theLoadPatterns->getNumComponents();
01771 
01772   // add the database tag for the ID's storing node, element, constraints
01773   // and loadpattern data into domainData
01774   // NOTE: if these still 0 get new ones from the channel
01775   if (dbNod == 0) {
01776     domainData(6) = dbNod = theChannel.getDbTag();
01777     domainData(7) = dbEle = theChannel.getDbTag();
01778     domainData(8) = dbSPs = theChannel.getDbTag();
01779     domainData(9) = dbMPs = theChannel.getDbTag();
01780     domainData(10) = dbLPs = theChannel.getDbTag();
01781   } else {
01782     domainData(6) = dbNod;
01783     domainData(7) = dbEle;
01784     domainData(8) = dbSPs;
01785     domainData(9) = dbMPs;
01786     domainData(10) = dbLPs;
01787   }
01788 
01789     cerr << "DOMAIN::domainData: " << domainData;  
01790   
01791   if (theChannel.sendID(theDbTag, commitTag, domainData) < 0) {
01792     g3ErrorHandler->warning("Domain::send - channel failed to send the initial ID");
01793     return -1;
01794   }    
01795 
01796   // send the time information
01797   Vector domainTime(2);
01798   domainTime(0) = currentTime;
01799   domainTime(1) = committedTime;
01800   if (theChannel.sendVector(theDbTag, commitTag, domainTime) < 0) {
01801     g3ErrorHandler->warning("Domain::send - channel failed to send the time Vector");
01802     return -2;
01803   }    
01804 
01805   // now check if data defining the objects in the domain needs to be sent 
01806   // NOTE THIS APPROACH MAY NEED TO CHANGE FOR VERY LARGE PROBLEMS IF CHANNEL CANNOT
01807   // HANDLE VERY LARGE ID OBJECTS.
01808   if (lastGeoSendTag != currentGeoTag) {
01809     
01810     //
01811     // into an ID we are gonna place the class and db tags for each node so can rebuild
01812     // this ID we then send to the channel
01813     //
01814 
01815     // create the ID and get the node iter
01816     if (numNod != 0) {
01817       ID nodeData(numNod*2);
01818       Node *theNode;
01819       NodeIter &theNodes = this->getNodes();
01820       int loc =0;
01821 
01822       // loop over nodes in domain adding their classTag and dbTag to the ID
01823       while ((theNode = theNodes()) != 0) {
01824  nodeData(loc) = theNode->getClassTag();
01825  int dbTag = theNode->getDbTag();
01826  
01827  // if dbTag still 0 get one from Channel; 
01828  // if this tag != 0 set the dbTag in node
01829  if (dbTag == 0) {// go get a new tag and setDbTag in ele if this not 0 
01830    dbTag = theChannel.getDbTag();
01831    if (dbTag != 0)
01832      theNode->setDbTag(dbTag);
01833  }
01834       
01835  nodeData(loc+1) = dbTag;
01836  loc+=2;
01837       }    
01838 
01839       // now send the ID
01840       if (theChannel.sendID(dbNod, currentGeoTag, nodeData) < 0) {
01841  g3ErrorHandler->warning("Domain::send - channel failed to send the node ID");
01842  return -2;
01843       }
01844     }
01845 
01846     // we do the same for elements as we did for nodes above .. see comments
01847     // for nodes if you can't figure whats going on!
01848 
01849     if (numEle != 0) {
01850       ID elementData(numEle*2);
01851       Element *theEle;
01852       ElementIter &theElements = this->getElements();
01853       int loc = 0;
01854     
01855       while ((theEle = theElements()) != 0) {
01856  elementData(loc) = theEle->getClassTag();
01857  int dbTag = theEle->getDbTag();
01858 
01859  if (dbTag == 0) {// go get a new tag and setDbTag in ele if this not 0 
01860    dbTag = theChannel.getDbTag();
01861    if (dbTag != 0)
01862      theEle->setDbTag(dbTag);
01863  }
01864       
01865  elementData(loc+1) = dbTag;
01866  loc+=2;
01867       }
01868 
01869       // now send the ID
01870       if (theChannel.sendID(dbEle, currentGeoTag, elementData) < 0) {
01871  g3ErrorHandler->warning("Domain::send - channel failed to send the element ID");
01872  return -3;
01873       }
01874     }
01875 
01876     // we do the same for SP_Constraints as for Nodes above .. see comments
01877     // for nodes if you can't figure whats going on!    
01878     
01879     if (numSPs != 0) {
01880       ID spData(numSPs*2);
01881       SP_Constraint *theSP;
01882       SP_ConstraintIter &theSPs = this->getSPs();
01883       int loc = 0;
01884     
01885       while ((theSP = theSPs()) != 0) {
01886  spData(loc) = theSP->getClassTag();
01887  int dbTag = theSP->getDbTag();
01888 
01889  if (dbTag == 0) {// go get a new tag and setDbTag in ele if this not 0 
01890    dbTag = theChannel.getDbTag();
01891    if (dbTag != 0)
01892      theSP->setDbTag(dbTag);
01893  }
01894  
01895  spData(loc+1) = dbTag;
01896  loc+=2;
01897       }    
01898 
01899       if (theChannel.sendID(dbSPs, currentGeoTag, spData) < 0) {
01900  g3ErrorHandler->warning("Domain::send - channel failed to send the SP_Constraint ID");
01901  return -4;
01902       }
01903     }
01904 
01905     // we do the same for MP_Constraints as for Nodes above .. see comments
01906     // for nodes if you can't figure whats going on!    
01907     
01908     if (numMPs != 0) {
01909       ID mpData(numMPs*2);
01910       MP_Constraint *theMP;
01911       MP_ConstraintIter &theMPs = this->getMPs();
01912       int loc = 0;
01913     
01914       while ((theMP = theMPs()) != 0) {
01915  mpData(loc) = theMP->getClassTag();
01916  int dbTag = theMP->getDbTag();
01917  
01918  if (dbTag == 0) {// go get a new tag and setDbTag in ele if this not 0 
01919    dbTag = theChannel.getDbTag();
01920    if (dbTag != 0)
01921      theMP->setDbTag(dbTag);
01922  }
01923       
01924  mpData(loc+1) = dbTag;
01925  loc+=2;
01926       }    
01927 
01928       if (theChannel.sendID(dbMPs, currentGeoTag, mpData) < 0) {
01929  g3ErrorHandler->warning("Domain::send - channel failed to send the MP_Constraint ID");
01930  return -5;
01931       }
01932     }
01933 
01934     // we do the same for LoadPatterns as we did for Nodes above .. see comments
01935     // for nodes if you can't figure whats going on!    
01936 
01937     if (numLPs != 0) {
01938       ID lpData(numLPs*2);
01939       LoadPattern *theLP;
01940       LoadPatternIter &theLPs = this->getLoadPatterns();
01941       int loc = 0;
01942     
01943       while ((theLP = theLPs()) != 0) {
01944  lpData(loc) = theLP->getClassTag();
01945  int dbTag = theLP->getDbTag();
01946 
01947  if (dbTag == 0) {// go get a new tag and setDbTag in ele if this not 0 
01948    dbTag = theChannel.getDbTag();
01949    if (dbTag != 0)
01950      theLP->setDbTag(dbTag);
01951  }
01952       
01953  lpData(loc+1) = dbTag;
01954  loc+=2;
01955       }    
01956 
01957       if (theChannel.sendID(dbLPs, currentGeoTag, lpData) < 0) {
01958  g3ErrorHandler->warning("Domain::send - channel failed to send the LoadPattern ID");
01959  return -6;
01960       }    
01961     }
01962 
01963 
01964     // now so that we don't do this next time if nothing in the domain has changed
01965     lastGeoSendTag = currentGeoTag;
01966   }
01967 
01968   //
01969   // now we invoke sendSelf on each of the objects .. 
01970   // NOTE: don't have to set the dbTags of the objects as just done this above
01971   //
01972 
01973   // send the nodes
01974   Node *theNode;
01975   NodeIter &theNodes = this->getNodes();
01976   while ((theNode = theNodes()) != 0) {
01977     if (theNode->sendSelf(commitTag, theChannel) < 0) {
01978       g3ErrorHandler->warning("Domain::send - node with tag %d failed in sendSelf",
01979          theNode->getTag());
01980       return -7;
01981     }
01982   }
01983 
01984   // send the elements
01985   Element *theEle;
01986   ElementIter &theElements = this->getElements();
01987   while ((theEle = theElements()) != 0) {
01988     if (theEle->sendSelf(commitTag, theChannel) < 0) {
01989       g3ErrorHandler->warning("Domain::send - element with tag %d failed in sendSelf",
01990          theEle->getTag());
01991       return -8;
01992     }
01993   }
01994 
01995   // send the single point constraints
01996   SP_Constraint *theSP;
01997   SP_ConstraintIter &theSPs = this->getSPs();
01998   while ((theSP = theSPs()) != 0) {
01999     if (theSP->sendSelf(commitTag, theChannel) < 0) {
02000       g3ErrorHandler->warning("Domain::send - SP_Constraint with tag %d failed in sendSelf",
02001          theSP->getTag());
02002       return -9;
02003     }
02004   }    
02005 
02006   // send the multi point constraints
02007   MP_Constraint *theMP;
02008   MP_ConstraintIter &theMPs = this->getMPs();
02009   while ((theMP = theMPs()) != 0) {
02010     if (theMP->sendSelf(commitTag, theChannel) < 0) {
02011       g3ErrorHandler->warning("Domain::send - MP_Constraint with tag %d failed in sendSelf",
02012          theMP->getTag());
02013       return -10;
02014     }
02015   }    
02016 
02017   // send the load patterns
02018   LoadPattern *theLP;
02019   LoadPatternIter &theLPs = this->getLoadPatterns();
02020   while ((theLP = theLPs()) != 0) {
02021     if (theLP->sendSelf(commitTag, theChannel) < 0) {
02022       g3ErrorHandler->warning("Domain::send - LoadPattern with tag %d failed in sendSelf",
02023          theLP->getTag());
02024       return -11;
02025     }
02026   }  
02027 
02028   // if get here we were successfull
02029   return commitTag;
02030 }
02031 
02032 
02033 int 
02034 Domain::recvSelf(int cTag, Channel &theChannel, FEM_ObjectBroker &theBroker) 
02035 {
02036   // set the commitTag in the domain to cTag & update the getTag if needed
02037   commitTag = cTag;
02038   this->hasDomainChanged();
02039 
02040   // first we get the data about the state of the domain for this commitTag
02041   ID domainData(11);
02042   if (theChannel.recvID(theDbTag, commitTag, domainData) < 0) {
02043     g3ErrorHandler->warning("Domain::recv - channel failed to recv the initial ID");
02044     return -1;
02045   }
02046 
02047 
02048   // recv the time information
02049   Vector domainTime(2);
02050   if (theChannel.recvVector(theDbTag, commitTag, domainTime) < 0) {
02051     g3ErrorHandler->warning("Domain::send - channel failed to recv thetime Vector");
02052     return -1;
02053   }    
02054   currentTime = domainTime(0);
02055   committedTime = domainTime(1);
02056 
02057 
02058   // 
02059   // now if the currentGeoTag does not agree with whats in the domain
02060   // we must wipe everything in the domain and recreate the domain based on the info from the channel
02061   //
02062   if (domainData(0) != currentGeoTag) {
02063     
02064     // set the currrentGeoTag
02065     int geoTag = domainData(0);
02066 
02067     int i, loc;
02068     int numEle, numNod, numSPs, numMPs, numLPs;
02069 
02070     // if receiving set lastGeoSendTag to be equal to currentGeoTag 
02071     // at time all the data was sent if not we must clear out the objects and rebuild
02072     lastGeoSendTag = domainData(0);
02073 
02074     // clear out the all the components in the current domain
02075     this->clearAll();
02076 
02077     // 
02078     // now we rebuild the nodes
02079     //
02080     
02081     // first get the information from the domainData about the nodes
02082     numNod = domainData(1);
02083     dbNod = domainData(6);
02084     
02085     cerr << "DOMAIN::numNode: " << numNod << " domainData: " << domainData;
02086     if (numNod != 0) {
02087       ID nodeData(2*numNod);
02088 
02089       // now receive the ID about the nodes, class tag and dbTags
02090       if (theChannel.recvID(dbNod, geoTag, nodeData) < 0) {
02091  g3ErrorHandler->warning("Domain::recv - channel failed to recv the node ID");
02092  return -2;
02093       }
02094 
02095       // now for each node we 1) get a new node of the correct type from the ObjectBroker
02096       // 2) ensure the node exists and set it's dbTag, 3) we invoke recvSelf on this new 
02097       // blank node and 4) add this node to the domain
02098       loc = 0;
02099       for (i=0; i<numNod; i++) {
02100  int classTag = nodeData(loc);
02101  int dbTag = nodeData(loc+1);
02102       
02103  Node *theNode = theBroker.getNewNode(classTag);
02104 
02105  if (theNode == 0) {
02106    g3ErrorHandler->warning("Domain::recv - cannot create node with classTag %d ",
02107       classTag);
02108    return -2;
02109  }   
02110 
02111  theNode->setDbTag(dbTag);
02112       
02113  if (theNode->recvSelf(commitTag, theChannel, theBroker) < 0) {
02114    g3ErrorHandler->warning("Domain::recv - node with dbTag %d failed in recvSelf",
02115       dbTag);
02116    return -2;
02117  }   
02118 
02119  if (this->addNode(theNode) == false) {
02120    g3ErrorHandler->warning("Domain::recv - could not add node with tag %d into domain!",
02121     theNode->getTag());
02122    return -3;
02123  }   
02124 
02125  loc+=2;
02126       }
02127     }
02128 
02129     // 
02130     // now we rebuild the elements .. same as nodes above .. see above if can't understand!!
02131     //
02132     
02133     numEle = domainData(2);
02134     dbEle = domainData(7);
02135 
02136     if (numEle != 0) {
02137       ID eleData(2*numEle);
02138 
02139       if (theChannel.recvID(dbEle, geoTag, eleData) < 0) {
02140  g3ErrorHandler->warning("Domain::recv - channel failed to recv the Elee ID");
02141  return -2;
02142       }
02143 
02144       loc = 0;
02145       for (i=0; i<numEle; i++) {
02146  int classTag = eleData(loc);
02147  int dbTag = eleData(loc+1);
02148       
02149  Element *theEle = theBroker.getNewElement(classTag);
02150  if (theEle == 0) {
02151    g3ErrorHandler->warning("Domain::recv - cannot create element with classTag %d ",
02152       classTag);
02153    return -2;
02154  }   
02155  theEle->setDbTag(dbTag);
02156       
02157  if (theEle->recvSelf(commitTag, theChannel, theBroker) < 0) {
02158    g3ErrorHandler->warning("Domain::recv - Ele with dbTag %d failed in recvSelf",
02159       dbTag);
02160    return -2;
02161  }   
02162 
02163  if (this->addElement(theEle) == false) {
02164    g3ErrorHandler->warning("Domain::recv - could not add Ele with tag %d into domain!",
02165       theEle->getTag());
02166    return -3;
02167  }   
02168 
02169  loc+=2;
02170       }
02171     }
02172 
02173     // 
02174     // now we rebuild the SP_Constraints .. same as nodes above .. see above if can't understand!!
02175     //
02176     
02177     numSPs = domainData(3);
02178     dbSPs = domainData(8);
02179     
02180     if (numSPs != 0) {
02181       ID spData(2*numSPs);
02182 
02183       if (theChannel.recvID(dbSPs, geoTag, spData) < 0) {
02184  g3ErrorHandler->warning("Domain::recv - channel failed to recv the SP_Constraints ID");
02185  return -2;
02186       }
02187 
02188       loc = 0;
02189       for (i=0; i<numSPs; i++) {
02190  int classTag = spData(loc);
02191  int dbTag = spData(loc+1);
02192       
02193  SP_Constraint *theSP = theBroker.getNewSP(classTag);
02194  if (theSP == 0) {
02195    g3ErrorHandler->warning("Domain::recv - cannot create SP_Constraint with classTag %d ",
02196       classTag);
02197    return -2;
02198  }   
02199  theSP->setDbTag(dbTag);
02200       
02201  if (theSP->recvSelf(commitTag, theChannel, theBroker) < 0) {
02202    g3ErrorHandler->warning("Domain::recv - SP_Constraint with dbTag %d failed in recvSelf",
02203       dbTag);
02204    return -2;
02205  }   
02206 
02207  if (this->addSP_Constraint(theSP) == false) {
02208    g3ErrorHandler->warning("Domain::recv - could not add SP_Constraint with tag %d into domain!",
02209       theSP->getTag());
02210    return -3;
02211  }   
02212 
02213  loc+=2;
02214       }
02215     }
02216 
02217 
02218     // 
02219     // now we rebuild the MP_Constraints .. same as nodes above .. see above if can't understand!!
02220     //
02221     
02222     numMPs = domainData(4);
02223     dbMPs = domainData(9);
02224 
02225     if (numMPs != 0) {
02226       ID mpData(2*numMPs);
02227 
02228       if (theChannel.recvID(dbMPs, geoTag, mpData) < 0) {
02229  g3ErrorHandler->warning("Domain::recv - channel failed to recv the MP_Constraints ID");
02230  return -2;
02231       }
02232 
02233       loc = 0;
02234       for (i=0; i<numMPs; i++) {
02235  int classTag = mpData(loc);
02236  int dbTag = mpData(loc+1);
02237       
02238  MP_Constraint *theMP = theBroker.getNewMP(classTag);
02239  if (theMP == 0) {
02240    g3ErrorHandler->warning("Domain::recv - cannot create MP_Constraint with classTag %d ",
02241       classTag);
02242    return -2;
02243  }   
02244  theMP->setDbTag(dbTag);
02245       
02246  if (theMP->recvSelf(commitTag, theChannel, theBroker) < 0) {
02247    g3ErrorHandler->warning("Domain::recv - MP_Constraint with dbTag %d failed in recvSelf",
02248       dbTag);
02249    return -2;
02250  }   
02251 
02252  if (this->addMP_Constraint(theMP) == false) {
02253    g3ErrorHandler->warning("Domain::recv - could not add MP_Constraint with tag %d into domain!",
02254       theMP->getTag());
02255    return -3;
02256  }   
02257  
02258  loc+=2;
02259       }
02260     }
02261 
02262     // 
02263     // now we rebuild the LoadPatterns .. same as nodes above .. see above if can't understand!!
02264     //
02265     
02266     numLPs = domainData(5);
02267     dbLPs = domainData(10);
02268 
02269     if (numLPs != 0) {
02270       ID lpData(2*numLPs);
02271       
02272       if (theChannel.recvID(dbLPs, geoTag, lpData) < 0) {
02273  g3ErrorHandler->warning("Domain::recv - channel failed to recv the MP_Constraints ID");
02274  return -2;
02275       }
02276 
02277       loc = 0;
02278       for (i=0; i<numLPs; i++) {
02279  int classTag = lpData(loc);
02280  int dbTag = lpData(loc+1);
02281       
02282  LoadPattern *theLP = theBroker.getNewLoadPattern(classTag);
02283  if (theLP == 0) {
02284    g3ErrorHandler->warning("Domain::recv - cannot create MP_Constraint with classTag %d ",
02285       classTag);
02286    return -2;
02287  }   
02288  theLP->setDbTag(dbTag);
02289       
02290  if (theLP->recvSelf(commitTag, theChannel, theBroker) < 0) {
02291    g3ErrorHandler->warning("Domain::recv - LoadPattern with dbTag %d failed in recvSelf",
02292       dbTag);
02293    return -2;
02294  }   
02295 
02296  if (this->addLoadPattern(theLP) == false) {
02297    g3ErrorHandler->warning("Domain::recv - could not add LoadPattern with tag %d into domain!",
02298       theLP->getTag());
02299    return -3;
02300  }   
02301 
02302  loc+=2;
02303       }
02304     }
02305 
02306     // set the currentGeoTag & mark domainChangeFlag as false
02307     // this way if restoring froma a database and domain has not changed for the analysis
02308     // the analysis will not have to to do a domainChanged() operation
02309     currentGeoTag = domainData(0);
02310 
02311     lastGeoSendTag = currentGeoTag;
02312     hasDomainChangedFlag = false;
02313 
02314   } else {
02315 
02316     // in this block .. we have the components they just have to recv themselves again
02317     
02318     Node *theNode;
02319     NodeIter &theNodes = this->getNodes();
02320     while ((theNode = theNodes()) != 0) {
02321       if (theNode->recvSelf(commitTag, theChannel, theBroker) < 0) {
02322  g3ErrorHandler->warning("Domain::recv - node with tag %d failed in recvSelf",
02323     theNode->getTag());
02324  return -7;
02325       }
02326     }
02327 
02328     Element *theEle;
02329     ElementIter &theElements = this->getElements();
02330     while ((theEle = theElements()) != 0) {
02331       if (theEle->recvSelf(commitTag, theChannel, theBroker) < 0) {
02332  g3ErrorHandler->warning("Domain::recv - element with tag %d failed in recvSelf",
02333     theEle->getTag());
02334  return -8;
02335       }
02336     }
02337 
02338     SP_Constraint *theSP;
02339     SP_ConstraintIter &theSPs = this->getSPs();
02340     while ((theSP = theSPs()) != 0) {
02341       if (theSP->recvSelf(commitTag, theChannel, theBroker) < 0) {
02342  g3ErrorHandler->warning("Domain::recv - SP_Constraint with tag %d failed in recvSelf",
02343     theSP->getTag());
02344  return -9;
02345       }
02346     }    
02347 
02348     MP_Constraint *theMP;
02349     MP_ConstraintIter &theMPs = this->getMPs();
02350     while ((theMP = theMPs()) != 0) {
02351       if (theMP->recvSelf(commitTag, theChannel, theBroker) < 0) {
02352  g3ErrorHandler->warning("Domain::recv - MP_Constraint with tag %d failed in recvSelf",
02353     theMP->getTag());
02354  return -10;
02355       }
02356     }    
02357 
02358     LoadPattern *theLP;
02359     LoadPatternIter &theLPs = this->getLoadPatterns();
02360     while ((theLP = theLPs()) != 0) {
02361       if (theLP->recvSelf(commitTag, theChannel, theBroker) < 0) {
02362  g3ErrorHandler->warning("Domain::recv - LoadPattern with tag %d failed in recvSelf",
02363     theLP->getTag());
02364  return -11;
02365       }
02366     }  
02367 
02368   } 
02369 
02370   // now set the domains lastGeoSendTag and currentDomainChangedFlag
02371   lastGeoSendTag = currentGeoTag;  
02372 
02373   // if get here we were successfull
02374   return 0;
02375 }
02376 
Copyright Contact Us