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

Node.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/07/26 00:58:59 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/domain/node/Node.cpp,v $
00024                                                                         
00025                                                                         
00026 // File: ~/domain/node/Node.C
00027 //
00028 // Written: fmk 
00029 // Created: 11/96
00030 // Revision: A
00031 //
00032 // This file contains the implementation of the Node class
00033 //
00034 // What: "@(#) Node.h, revA"
00035    
00036 #include <Node.h>
00037 #include <stdlib.h>
00038 
00039 #include <Element.h>
00040 #include <Vector.h>
00041 #include <Matrix.h>
00042 #include <Channel.h>
00043 #include <FEM_ObjectBroker.h>
00044 #include <DOF_Group.h>
00045 #include <Renderer.h>
00046 #include <string.h>
00047 #include <G3Globals.h>
00048 
00049 // for FEM_Object Broker to use
00050 Node::Node(int theClassTag)
00051 :DomainComponent(0,theClassTag), 
00052  numberDOF(0), theDOF_GroupPtr(0), 
00053  Crd(0), commitDisp(0), commitVel(0), commitAccel(0), 
00054  trialDisp(0), trialVel(0), trialAccel(0), unbalLoad(0), incrDisp(0), 
00055  incrDeltaDisp(0),
00056  disp(0), vel(0), accel(0), dbTag1(0), dbTag2(0), dbTag3(0), dbTag4(0),
00057  R(0), mass(0), unbalLoadWithInertia(0), theEigenvectors(0)
00058 {
00059     // for FEM_ObjectBroker, recvSelf() must be invoked on object
00060 }    
00061 
00062 
00063 Node::Node(int tag, int theClassTag)
00064 :DomainComponent(tag,theClassTag), 
00065  numberDOF(0), theDOF_GroupPtr(0), 
00066  Crd(0), commitDisp(0), commitVel(0), commitAccel(0), 
00067  trialDisp(0), trialVel(0), trialAccel(0), unbalLoad(0), incrDisp(0),
00068  incrDeltaDisp(0), 
00069  disp(0), vel(0), accel(0), dbTag1(0), dbTag2(0), dbTag3(0), dbTag4(0),
00070  R(0), mass(0), unbalLoadWithInertia(0), theEigenvectors(0)
00071 {
00072     // for subclasses - they must implement all the methods with
00073     // their own data structures.
00074 }
00075 
00076 Node::Node(int tag, int ndof, double Crd1)
00077 :DomainComponent(tag,NOD_TAG_Node), 
00078  numberDOF(ndof), theDOF_GroupPtr(0),
00079  Crd(0), commitDisp(0), commitVel(0), commitAccel(0), 
00080  trialDisp(0), trialVel(0), trialAccel(0), unbalLoad(0), incrDisp(0),
00081  incrDeltaDisp(0), 
00082  disp(0), vel(0), accel(0), dbTag1(0), dbTag2(0), dbTag3(0), dbTag4(0),
00083  R(0), mass(0), unbalLoadWithInertia(0), theEigenvectors(0)
00084 {
00085     Crd = new Vector(1);
00086     (*Crd)(0) = Crd1;
00087 }
00088 
00089 
00090 //  Node(int tag, int ndof, double Crd1, double yCrd);
00091 // constructor for 2d nodes
00092 Node::Node(int tag, int ndof, double Crd1, double Crd2)
00093 :DomainComponent(tag,NOD_TAG_Node), 
00094  numberDOF(ndof), theDOF_GroupPtr(0),
00095  Crd(0), commitDisp(0), commitVel(0), commitAccel(0), 
00096  trialDisp(0), trialVel(0), trialAccel(0), unbalLoad(0), incrDisp(0),
00097  incrDeltaDisp(0), 
00098  disp(0), vel(0), accel(0), dbTag1(0), dbTag2(0), dbTag3(0), dbTag4(0),
00099  R(0), mass(0), unbalLoadWithInertia(0), theEigenvectors(0)
00100 {
00101     Crd = new Vector(2);
00102     (*Crd)(0) = Crd1;
00103     (*Crd)(1) = Crd2;
00104 }
00105 
00106 
00107 //  Node(int tag, int ndof, double Crd1, double Crd2, double zCrd);
00108 // constructor for 3d nodes
00109 
00110 Node::Node(int tag, int ndof, double Crd1, double Crd2, double Crd3)
00111 :DomainComponent(tag,NOD_TAG_Node), 
00112  numberDOF(ndof), theDOF_GroupPtr(0),
00113  Crd(0), commitDisp(0), commitVel(0), commitAccel(0), 
00114  trialDisp(0), trialVel(0), trialAccel(0), unbalLoad(0), incrDisp(0),
00115  incrDeltaDisp(0), 
00116  disp(0), vel(0), accel(0), dbTag1(0), dbTag2(0), dbTag3(0), dbTag4(0),
00117  R(0), mass(0), unbalLoadWithInertia(0), theEigenvectors(0)
00118 {
00119     Crd = new Vector(3);
00120     (*Crd)(0) = Crd1;
00121     (*Crd)(1) = Crd2;
00122     (*Crd)(2) = Crd3;    
00123 }
00124 
00125 
00126 
00127 Node::Node(const Node *otherNode)
00128 :DomainComponent(otherNode->getTag(),NOD_TAG_Node), 
00129  numberDOF(otherNode->numberDOF), theDOF_GroupPtr(0),
00130  Crd(0), commitDisp(0), commitVel(0), commitAccel(0), 
00131  trialDisp(0), trialVel(0), trialAccel(0), unbalLoad(0), incrDisp(0),
00132  incrDeltaDisp(0), 
00133  disp(0), vel(0), accel(0), dbTag1(0), dbTag2(0), dbTag3(0), dbTag4(0),
00134  R(0), mass(0), unbalLoadWithInertia(0), theEigenvectors(0)
00135 {
00136     if (otherNode->Crd != 0) {
00137  Crd = new Vector(*(otherNode->Crd));
00138  if (Crd == 0) {
00139      cerr << " FATAL Node::Node(node *) - ran out of memory for Crd\n";
00140      exit(-1);
00141  }
00142     }
00143 
00144     if (otherNode->commitDisp != 0) {
00145  if (this->createDisp() < 0) {
00146      cerr << " FATAL Node::Node(node *) - ran out of memory for displacement\n";
00147      exit(-1);
00148  }
00149  for (int i=0; i<3*numberDOF; i++)
00150      disp[i] = otherNode->disp[i];
00151     }    
00152     
00153     if (otherNode->commitVel != 0) {
00154  if (this->createVel() < 0) {
00155      cerr << " FATAL Node::Node(node *) - ran out of memory for velocity\n";
00156      exit(-1);
00157  }
00158  for (int i=0; i<2*numberDOF; i++)
00159      vel[i] = otherNode->vel[i];
00160     }    
00161     
00162     if (otherNode->commitAccel != 0) {
00163  if (this->createAccel() < 0) {
00164      cerr << " FATAL Node::Node(node *) - ran out of memory for acceleration\n";
00165      exit(-1);
00166  }
00167  for (int i=0; i<2*numberDOF; i++)
00168      accel[i] = otherNode->accel[i];
00169     }    
00170 
00171     if (otherNode->unbalLoad != 0){
00172  unbalLoad = new Vector(*(otherNode->unbalLoad));    
00173  if (unbalLoad == 0) {
00174      cerr << " FATAL Node::Node(node *) - ran out of memory for Load\n";
00175      exit(-1);
00176  }
00177     }    
00178 
00179     if (otherNode->mass != 0) {
00180  mass = new Matrix(*(otherNode->mass)) ;
00181  if (mass == 0) {
00182      cerr << " FATAL Node::Node(node *) - ran out of memory for mass\n";
00183      exit(-1);
00184  }
00185     }
00186     if (otherNode->R != 0) {
00187       R = new Matrix(*(otherNode->R));
00188  if (R == 0) {
00189      cerr << " FATAL Node::Node(node *) - ran out of memory for R\n";
00190      exit(-1);
00191  }
00192     }
00193 }
00194 
00195 
00196 // ~Node():
00197 //  destructor
00198 
00199 Node::~Node()
00200 {
00201     // delete anything that we created with new
00202     if (Crd != 0)
00203  delete Crd;
00204 
00205     if (commitDisp != 0)
00206  delete commitDisp;
00207 
00208     if (commitVel != 0)
00209  delete commitVel;
00210 
00211     if (commitAccel != 0)
00212  delete commitAccel;
00213 
00214     if (trialDisp != 0)
00215  delete trialDisp;
00216 
00217     if (trialVel != 0)
00218  delete trialVel;
00219 
00220     if (trialAccel != 0)
00221  delete trialAccel;
00222 
00223     if (incrDisp != 0)
00224  delete incrDisp;
00225     
00226     if (incrDeltaDisp != 0)
00227  delete incrDeltaDisp;    
00228     
00229     if (unbalLoad != 0)
00230  delete unbalLoad;
00231     
00232     if (disp != 0)
00233  delete [] disp;
00234 
00235     if (vel != 0)
00236  delete [] vel;
00237 
00238     if (accel != 0)
00239  delete [] accel;
00240 
00241     if (mass != 0)
00242  delete mass;
00243     
00244     if (R != 0)
00245  delete R;
00246 
00247     if (unbalLoadWithInertia != 0)
00248       delete unbalLoadWithInertia;
00249 
00250     if (theEigenvectors != 0)
00251       delete theEigenvectors;
00252 }
00253 
00254 
00255 int
00256 Node::getNumberDOF(void) const
00257 {
00258     // return the number of dof
00259     return  numberDOF;
00260 }
00261 
00262 
00263 void
00264 Node::setDOF_GroupPtr(DOF_Group *theDOF_Grp)
00265 {
00266     // set the DOF_Group pointer
00267     theDOF_GroupPtr = theDOF_Grp;
00268 }
00269 
00270 
00271 DOF_Group *
00272 Node::getDOF_GroupPtr(void)
00273 {
00274     // return the DOF_Group pointer
00275     return theDOF_GroupPtr;
00276 }
00277 
00278 
00279 const Vector &
00280 Node::getCrds() const
00281 {
00282     // return the vector of nodal coordinates
00283     return *Crd;
00284 }
00285 
00286 
00287 
00288 
00289 const Vector &
00290 Node::getDisp(void) 
00291 {
00292     // construct memory and Vectors for trial and committed
00293     // displacement on first call to this method, getTrialDisp()
00294     // setTrialDisp() or incrTrialDisp()
00295     if (commitDisp == 0) {
00296  if (this->createDisp() < 0) {
00297      cerr << "FATAL Node::getDisp() -- ran out of memory\n";
00298      exit(-1);
00299  }
00300     }
00301     
00302     // return the committed disp
00303     return *commitDisp;
00304 }
00305 
00306 const Vector &
00307 Node::getVel(void) 
00308 {
00309     // construct memory and Vectors for trial and committed
00310     // velocity on first call to this method, getTrialVel()
00311     // setTrialVel() or incrTrialVel()    
00312     if (commitVel == 0) {
00313  if (this->createVel() < 0) {
00314      cerr << "FATAL Node::getVel() -- ran out of memory\n";
00315      exit(-1);
00316  }
00317     }    
00318 
00319     // return the velocity
00320     return *commitVel;    
00321 }
00322 
00323 
00324 const Vector &
00325 Node::getAccel(void) 
00326 {
00327     // construct memory and Vectors for trial and committed
00328     // accel on first call to this method, getTrialAccel()
00329     // setTrialAccel() or incrTrialAccel()        
00330     if (commitAccel == 0) {
00331  if (this->createAccel() < 0) {
00332      cerr << "FATAL Node::getAccel() -- ran out of memory\n";
00333      exit(-1);
00334  }
00335     }
00336 
00337     return *commitAccel;    
00338 }
00339 
00340 
00341 /* *********************************************************************
00342 **
00343 **   Methods to return the trial response quantities similar to committed
00344 **
00345 ** *********************************************************************/
00346 
00347 const Vector &
00348 Node::getTrialDisp(void) 
00349 {
00350     if (trialDisp == 0) {
00351  if (this->createDisp() < 0) {
00352      cerr << "FATAL Node::getTrialDisp() -- ran out of memory\n";
00353      exit(-1);
00354  }
00355     }    
00356 
00357     return *trialDisp;
00358 }
00359 
00360 
00361 
00362 const Vector &
00363 Node::getTrialVel(void) 
00364 {
00365     if (trialVel == 0) {
00366  if (this->createVel() < 0) {
00367      cerr << "FATAL Node::getTrialVel() -- ran out of memory\n";
00368      exit(-1);
00369  }
00370     }    
00371 
00372     return *trialVel;
00373 }
00374 
00375 
00376 
00377 const Vector &
00378 Node::getTrialAccel(void) 
00379 {
00380     if (trialAccel == 0) {
00381  if (this->createAccel() < 0) {
00382      cerr << "FATAL Node::getTrialAccel() - ran out of memory\n";
00383      exit(0);
00384  }
00385     }    
00386     return *trialAccel;
00387 }
00388 
00389 const Vector &
00390 Node::getIncrDisp(void) 
00391 {
00392     if (incrDisp == 0) {
00393  if (this->createDisp() < 0) {
00394      cerr << "FATAL Node::getTrialDisp() -- ran out of memory\n";
00395      exit(-1);
00396  }
00397     }    
00398 
00399     return *incrDisp;
00400 }
00401 
00402 const Vector &
00403 Node::getIncrDeltaDisp(void) 
00404 {
00405     if (incrDeltaDisp == 0) {
00406  if (this->createDisp() < 0) {
00407      cerr << "FATAL Node::getTrialDisp() -- ran out of memory\n";
00408      exit(-1);
00409  }
00410     }    
00411 
00412     return *incrDeltaDisp;
00413 }
00414 
00415 
00416 int
00417 Node::setTrialDisp(const Vector &newTrialDisp)
00418 {
00419     // check vector arg is of correct size
00420     if (newTrialDisp.Size() != numberDOF) {
00421      cerr << "WARNING Node::setTrialDisp() - incompatable sizes\n";
00422      return -2;
00423  }    
00424 
00425     // construct memory and Vectors for trial and committed
00426     // accel on first call to this method, getTrialDisp(),
00427     // getDisp(), or incrTrialDisp()        
00428     if (trialDisp == 0) {
00429  if (this->createDisp() < 0) {
00430      cerr << "FATAL Node::setTrialDisp() - ran out of memory\n";
00431      exit(-1);
00432  }    
00433     }
00434 
00435     // perform the assignment .. we dont't go through Vector interface
00436     // as we are sure of size and this way is quicker
00437     for (int i=0; i<numberDOF; i++) {
00438         double tDisp = newTrialDisp(i);
00439  disp[i+2*numberDOF] = tDisp - disp[i+numberDOF];
00440  disp[i+3*numberDOF] = tDisp - disp[i]; 
00441  disp[i] = tDisp;
00442     }
00443 
00444     return 0;
00445 }
00446 
00447 int
00448 Node::setTrialVel(const Vector &newTrialVel)
00449 {
00450     // check vector arg is of correct size
00451     if (newTrialVel.Size() != numberDOF) {
00452      cerr << "WARNING Node::setTrialVel() - incompatable sizes\n";
00453      return -2;
00454     }    
00455 
00456     // construct memory and Vectors for trial and committed
00457     // accel on first call to this method, getTrialVEl(),
00458     // getVEl(), or incrTrialVel()        
00459     if (trialVel == 0) {
00460  if (this->createVel() < 0) {
00461      cerr << "FATAL Node::setTrialVel() - ran out of memory\n";
00462      exit(-1);
00463  }
00464     }      
00465     
00466     // set the trial quantities
00467     for (int i=0; i<numberDOF; i++)
00468  vel[i] = newTrialVel(i);
00469     return 0;
00470 }
00471 
00472 
00473 int
00474 Node::setTrialAccel(const Vector &newTrialAccel)
00475 {
00476     // check vector arg is of correct size
00477     if (newTrialAccel.Size() != numberDOF) {
00478      cerr << "WARNING Node::setTrialAccel() - incompatable sizes\n";
00479      return -2;
00480     }    
00481 
00482     // create a copy if no trial exists    
00483     if (trialAccel == 0) {
00484  if (this->createAccel() < 0) {
00485      cerr << "FATAL Node::setTrialAccel() - ran out of memory\n";
00486      exit(-1);
00487  }
00488     }        
00489     
00490     // use vector assignment otherwise        
00491     for (int i=0; i<numberDOF; i++)
00492  accel[i] = newTrialAccel(i);
00493 
00494     return 0;
00495 }
00496 
00497 int
00498 Node::incrTrialDisp(const Vector &incrDispl)
00499 {
00500     // check vector arg is of correct size
00501     if (incrDispl.Size() != numberDOF) {
00502  cerr << "WARNING Node::incrTrialDisp() - incompatable sizes\n";
00503  return -2;
00504     }    
00505 
00506     // create a copy if no trial exists andd add committed
00507     if (trialDisp == 0) {
00508  if (this->createDisp() < 0) {
00509      cerr << "FATAL Node::incrTrialDisp() - ran out of memory\n";
00510      exit(-1);
00511  }    
00512  for (int i = 0; i<numberDOF; i++) {
00513    double incrDispI = incrDispl(i);
00514    disp[i] = incrDispI;
00515    disp[i+2*numberDOF] = incrDispI;
00516    disp[i+3*numberDOF] = incrDispI;
00517  }
00518  return 0;
00519     }
00520 
00521     // otherwise set trial = incr + trial
00522     for (int i = 0; i<numberDOF; i++) {
00523    double incrDispI = incrDispl(i);
00524    disp[i] += incrDispI;
00525    disp[i+2*numberDOF] += incrDispI;
00526    disp[i+3*numberDOF] = incrDispI;
00527     }
00528 
00529     return 0;
00530 }
00531 
00532 
00533 int
00534 Node::incrTrialVel(const Vector &incrVel)
00535 {
00536     // check vector arg is of correct size
00537     if (incrVel.Size() != numberDOF) {
00538  cerr << "WARNING Node::incrTrialVel() - incompatable sizes\n";
00539  return -2;
00540     }    
00541 
00542     // create Vectors and array if none exist and set trial
00543     if (trialVel == 0) {
00544  if (this->createVel() < 0) {
00545      cerr << "FATAL Node::incrTrialVel - ran out of memory\n";
00546      exit(-1);
00547  }    
00548  for (int i = 0; i<numberDOF; i++)
00549      vel[i] = incrVel(i);
00550 
00551  return 0;
00552     }
00553 
00554     // otherwise set trial = incr + trial
00555     for (int i = 0; i<numberDOF; i++)
00556  vel[i] += incrVel(i);    
00557 
00558     return 0;
00559 }
00560 
00561 
00562 int
00563 Node::incrTrialAccel(const Vector &incrAccel)
00564 {
00565     // check vector arg is of correct size
00566     if (incrAccel.Size() != numberDOF) {
00567  cerr << "WARNING Node::incrTrialAccel() - incompatable sizes\n";
00568  return -2;
00569     }    
00570 
00571     // create a copy if no trial exists andd add committed    
00572     if (trialAccel == 0) {
00573  if (this->createAccel() < 0) {
00574      cerr << "FATAL Node::incrTrialAccel() - ran out of memory\n";
00575      exit(-1);
00576  }    
00577  for (int i = 0; i<numberDOF; i++)
00578      accel[i] = incrAccel(i);
00579 
00580  return 0;
00581     }
00582 
00583     // otherwise set trial = incr + trial
00584     for (int i = 0; i<numberDOF; i++)
00585  accel[i] += incrAccel(i);    
00586 
00587     return 0;
00588 }
00589 
00590 
00591 void 
00592 Node::zeroUnbalancedLoad(void)
00593 {
00594     if (unbalLoad != 0)
00595  unbalLoad->Zero();
00596 }
00597 
00598 int
00599 Node::addUnbalancedLoad(const Vector &add, double fact)
00600 {
00601     // check vector arg is of correct size
00602     if (add.Size() != numberDOF) {
00603  cerr << "Node::addunbalLoad - load to add of incorrect size ";
00604  cerr << add.Size() << " should be " <<  numberDOF << endl; 
00605  return -1;
00606     }
00607 
00608     // if no load yet create it and assign
00609     if (unbalLoad == 0) {
00610  unbalLoad = new Vector(add); 
00611  if (unbalLoad == 0) {
00612      cerr << "FATAL Node::addunbalLoad - ran out of memory\n";
00613      exit(-1);
00614  }
00615  if (fact != 1.0)
00616      (*unbalLoad) *= fact;
00617  return 0;
00618     }
00619 
00620     // add fact*add to the unbalanced load
00621     unbalLoad->addVector(1.0, add,fact);
00622 
00623     return 0;
00624 }
00625 
00626 
00627 
00628 int
00629 Node::addInertiaLoadToUnbalance(const Vector &accelG, double fact)
00630 {
00631   // simply return if node has no mass or R matrix
00632   if (mass == 0 || R == 0)
00633     return 0;
00634 
00635   // otherwise we must determine MR accelG
00636   if (accelG.Size() != R->noCols()) {
00637     cerr << "Node::addInertiaLoadToUnbalance - accelG not of correct dimension";
00638     return -1;
00639   }
00640 
00641   // if no load yet create it and assign
00642   if (unbalLoad == 0) {
00643       unbalLoad = new Vector(numberDOF); 
00644       if (unbalLoad == 0 || unbalLoad->Size() != numberDOF) {
00645    cerr << "FATAL Node::addunbalLoad - ran out of memory\n";
00646    exit(-1);
00647       }  
00648   }
00649 
00650   // form - fact * M*R*accelG and add it to the unbalanced load
00651   (*unbalLoad) -= ((*mass) * (*R) * accelG)*fact;
00652 
00653   return 0;
00654 }
00655 
00656 
00657 
00658 const Vector &
00659 Node::getUnbalancedLoad(void) 
00660 {
00661     // make sure it was created before we return it
00662     if (unbalLoad == 0) {
00663  unbalLoad = new Vector(numberDOF);
00664  if (unbalLoad == 0 || unbalLoad->Size() != numberDOF) {
00665      cerr << "FATAL Node::getunbalLoad() -- ran out of memory\n";
00666      exit(-1);
00667  }
00668     }
00669 
00670     // return the unbalanced load
00671     return *unbalLoad;
00672 }
00673 
00674 
00675     
00676 const Vector &
00677 Node::getUnbalancedLoadIncInertia(void) 
00678 {
00679     // make sure it was created before we return it
00680     if (unbalLoadWithInertia == 0) {
00681  unbalLoadWithInertia = new Vector(this->getUnbalancedLoad());
00682  if (unbalLoadWithInertia == 0) {
00683      cerr << "FATAL Node::getunbalLoadWithInertia -- ran out of memory\n";
00684      exit(-1);
00685  }
00686     } else
00687       (*unbalLoadWithInertia) = this->getUnbalancedLoad();
00688 
00689     if (mass != 0) {
00690       const Vector &theAccel = this->getTrialAccel(); // in case accel not created
00691       unbalLoadWithInertia->addMatrixVector(1.0, *mass, theAccel, -1.0);
00692     }
00693 
00694     return *unbalLoadWithInertia;
00695 }
00696 
00697 
00698 
00699 int
00700 Node::commitState()
00701 {
00702     // check disp exists, if does set commit = trial, incr = 0.0
00703     if (trialDisp != 0) {
00704       for (int i=0; i<numberDOF; i++) {
00705  disp[i+numberDOF] = disp[i];  
00706         disp[i+2*numberDOF] = 0.0;
00707         disp[i+3*numberDOF] = 0.0;
00708       }
00709     }      
00710     
00711     // check vel exists, if does set commit = trial    
00712     if (trialVel != 0) {
00713       for (int i=0; i<numberDOF; i++)
00714  vel[i+numberDOF] = vel[i];
00715     }
00716     
00717     // check accel exists, if does set commit = trial        
00718     if (trialAccel != 0) {
00719       for (int i=0; i<numberDOF; i++)
00720  accel[i+numberDOF] = accel[i];
00721     }
00722 
00723     // if we get here we are done
00724     return 0;
00725 }
00726 
00727 
00728 
00729 int
00730 Node::revertToLastCommit()
00731 {
00732     // check disp exists, if does set trial = last commit, incr = 0
00733     if (disp != 0) {
00734       for (int i=0 ; i<numberDOF; i++) {
00735  disp[i] = disp[i+numberDOF];
00736  disp[i+2*numberDOF] = 0.0;
00737  disp[i+3*numberDOF] = 0.0;
00738       }
00739     }
00740     
00741     // check vel exists, if does set trial = last commit
00742     if (vel != 0) {
00743       for (int i=0 ; i<numberDOF; i++)
00744  vel[i] = vel[numberDOF+i];
00745     }
00746 
00747     // check accel exists, if does set trial = last commit
00748     if (accel != 0) {    
00749       for (int i=0 ; i<numberDOF; i++)
00750  accel[i] = accel[numberDOF+i];
00751     }
00752 
00753     // if we get here we are done
00754     return 0;
00755 }
00756 
00757 
00758 int
00759 Node::revertToStart()
00760 {
00761     // check disp exists, if does set all to zero
00762     if (disp != 0) {
00763       for (int i=0 ; i<4*numberDOF; i++)
00764  disp[i] = 0.0;
00765     }
00766 
00767     // check vel exists, if does set all to zero
00768     if (vel != 0) {
00769       for (int i=0 ; i<2*numberDOF; i++)
00770  vel[i] = 0.0;
00771     }
00772 
00773     // check accel exists, if does set all to zero
00774     if (accel != 0) {    
00775       for (int i=0 ; i<2*numberDOF; i++)
00776  accel[i] = 0.0;
00777     }
00778     
00779     if (unbalLoad != 0) 
00780  (*unbalLoad) *= 0;
00781 
00782     // if we get here we are done
00783     return 0;
00784 }
00785 
00786 
00787 const Matrix &
00788 Node::getMass(void) 
00789 {
00790     // make sure it was created before we return it
00791     if (mass == 0) {
00792  mass = new Matrix(numberDOF,numberDOF);
00793  if (mass == 0 || mass->noRows() != numberDOF) {
00794      cerr << "FATAL Node::GetMass() -- ran out of memory\n";
00795      exit(-1);
00796  }
00797     }
00798     
00799     return *mass;
00800 }
00801 
00802 
00803 
00804 int
00805 Node::setMass(const Matrix &newMass)
00806 {
00807     // check right size
00808     if (newMass.noRows() != numberDOF || newMass.noCols() != numberDOF) {
00809  cerr << "Node::setMass - incompatable matrices\n";
00810  return -1;
00811     } 
00812 
00813     // create a matrix if no mass yet set
00814     if (mass == 0) {
00815  mass = new Matrix(newMass);
00816  if (mass == 0 || mass->noRows() != numberDOF) {
00817      cerr << "FATAL Node::setMass - ran out of memory\n";
00818      return -1;
00819  }
00820  return 0;
00821     }
00822 
00823     // assign if mass has already been created
00824     (*mass) = newMass;
00825     
00826     return 0;
00827 }
00828 
00829 
00830 
00831 int 
00832 Node::setNumColR(int numCol)
00833 {
00834   if (R != 0) {
00835     if (R->noCols() != numCol) {
00836       delete R;
00837       R = new Matrix(numberDOF, numCol);
00838     }
00839   } else 
00840     R = new Matrix(numberDOF, numCol);
00841 
00842   if (R == 0 || R->noRows() != numberDOF) {
00843       cerr << "FATAL Node::setNumColR() - out of memory\n";
00844       exit(-1);
00845   }
00846 
00847   R->Zero();
00848   return 0;
00849 }  
00850 
00851 int 
00852 Node::setR(int row, int col, double Value)
00853 {
00854   // ensure R had been set
00855   if (R == 0) {
00856     cerr << "Node:setR() - R has not been initialised\n";
00857     return -1;
00858   }
00859   
00860   // ensure row, col in range (matrix assignment will catch this - extra work)
00861   if (row < 0 || row > numberDOF || col < 0 || col > R->noCols()) {
00862     cerr << "Node:setR() - row, col index out of range\n";
00863     return -1;
00864   }
00865 
00866   // do the assignment
00867   (*R)(row,col) = Value;
00868   return 0;
00869 }
00870 
00871 
00872 
00873 const Vector &
00874 Node::getRV(const Vector &V)
00875 {
00876     // we store the product of RV in unbalLoadWithInertia
00877 
00878     // make sure unbalLoadWithInertia was created, if not create it
00879     if (unbalLoadWithInertia == 0) {
00880  unbalLoadWithInertia = new Vector(numberDOF);
00881  if (unbalLoadWithInertia == 0) {
00882      cerr << "Node::getunbalLoadWithInertia -- ran out of memory\n";
00883      exit(-1);
00884  }
00885     } 
00886     
00887     // see if quick return , i.e. R == 0
00888     if (R == 0) {
00889  unbalLoadWithInertia->Zero();
00890  return *unbalLoadWithInertia;
00891     }
00892     
00893     // check dimesions of R and V
00894     if (R->noCols() != V.Size()) {
00895  cerr << "WARNING Node::getRV() - R and V of incompatable dimesions\n";
00896  cerr << "R: " << *R << "V: " << V;
00897  unbalLoadWithInertia->Zero();
00898  return *unbalLoadWithInertia;
00899     }    
00900 
00901     // determine the product
00902     (*unbalLoadWithInertia) = (*R) * V;
00903     return *unbalLoadWithInertia;
00904 }
00905 
00906 
00907 int 
00908 Node::setNumEigenvectors(int numVectorsToStore)
00909 {
00910   // ensure a positive number of vectors
00911   if (numVectorsToStore <= 0) {
00912       g3ErrorHandler->warning("Node::setNumEigenvectors() - %d < 0\n", 
00913          numVectorsToStore);
00914       return -1;
00915   }    
00916 
00917   // if matrix not yet assigned or not of correct size delete old and create new
00918   if (theEigenvectors == 0 || theEigenvectors->noCols() != numVectorsToStore) {
00919     if (theEigenvectors != 0)
00920       delete theEigenvectors;
00921 
00922 
00923     theEigenvectors = new Matrix(numberDOF, numVectorsToStore);
00924     if (theEigenvectors == 0 || theEigenvectors->noCols() != numVectorsToStore) {
00925       g3ErrorHandler->warning("Node::setNumEigenvectors() - out of memory\n");
00926       return -2;
00927     }
00928   } else
00929     // zero the eigenvector matrix
00930     theEigenvectors->Zero();
00931   
00932     return 0;
00933 }
00934 int 
00935 Node::setEigenvector(int mode, const Vector &eigenVector)
00936 {
00937   if (theEigenvectors == 0 || theEigenvectors->noCols() < mode) {
00938       g3ErrorHandler->warning("Node::setEigenvectors() - mode %d invalid\n", mode);
00939       return -1;
00940   }
00941 
00942   if (eigenVector.Size() != numberDOF) {
00943       g3ErrorHandler->warning("Node::setEigenvectors() - eigenvector of incorrect size\n");
00944       return -2;
00945   }
00946   // set the values
00947   for (int i=0; i<numberDOF; i++)
00948     (*theEigenvectors)(i, mode-1) = eigenVector(i);
00949 
00950   return 0;
00951 }
00952 const Matrix &
00953 Node::getEigenvectors(void)
00954 {
00955   // check the eigen vectors have been set
00956   if (theEigenvectors == 0)
00957     g3ErrorHandler->fatal("Node::getEigenvectors() - eigenvectors have not been set\n");
00958   
00959   return *theEigenvectors;
00960 }
00961 
00962 
00963 int 
00964 Node::sendSelf(int cTag, Channel &theChannel)
00965 {
00966     int dataTag = this->getDbTag();
00967 
00968     ID data(14);
00969     data(0) = this->getTag(); 
00970     data(1) = numberDOF; 
00971     
00972     // indicate whether vector quantaties have been formed
00973     if (disp == 0)       data(2) = 1; else data(2) = 0;
00974     if (vel == 0)        data(3) = 1; else data(3) = 0;
00975     if (accel == 0)      data(4) = 1; else data(4) = 0;
00976     if (mass == 0)       data(5) = 1; else data(5) = 0;
00977     if (unbalLoad  == 0) data(6) = 1; else data(6) = 0;    
00978     if (R == 0)   
00979  data(12) = 1; 
00980     else {
00981  data(12) = 0;        
00982  data(13) = R->noCols();
00983     }
00984 
00985     data(7) = Crd->Size();
00986 
00987     if (dbTag1 == 0)
00988       dbTag1 = theChannel.getDbTag();
00989     if (dbTag2 == 0)
00990       dbTag2 = theChannel.getDbTag();
00991     if (dbTag3 == 0)
00992       dbTag3 = theChannel.getDbTag();
00993     if (dbTag4 == 0)
00994       dbTag4 = theChannel.getDbTag();
00995 
00996     data(8) = dbTag1;
00997     data(9) = dbTag2;
00998     data(10) = dbTag3;
00999     data(11) = dbTag4;
01000 
01001     int res = 0;
01002 
01003     res = theChannel.sendID(dataTag, cTag, data);
01004     if (res < 0) {
01005       cerr << " Node::sendSelf() - failed to send ID data\n";
01006       return res;
01007     }
01008 
01009     res = theChannel.sendVector(dataTag, cTag, *Crd);
01010     if (res < 0) {
01011       cerr << " Node::sendSelf() - failed to send Vecor data\n";
01012       return res;
01013     }
01014 
01015     if (commitDisp != 0) {
01016  res = theChannel.sendVector(dbTag1, cTag, *commitDisp); 
01017  if (res < 0) {
01018    cerr << " Node::sendSelf() - failed to send Disp data\n";
01019    return res;
01020  }
01021     }
01022 
01023     if (commitVel != 0) {
01024  res = theChannel.sendVector(dbTag2, cTag, *commitVel);  
01025  if (res < 0) {
01026    cerr << " Node::sendSelf() - failed to send Vel data\n";
01027    return res;
01028  }
01029     }
01030 
01031     if (commitAccel != 0) {
01032  res = theChannel.sendVector(dbTag3, cTag, *commitAccel); 
01033  if (res < 0) {
01034    cerr << " Node::sendSelf() - failed to send Accel data\n";
01035    return res;
01036  }
01037     }
01038 
01039     if (mass != 0) {
01040  res = theChannel.sendMatrix(dataTag, cTag, *mass);
01041  if (res < 0) {
01042    cerr << " Node::sendSelf() - failed to send Mass data\n";
01043    return res;
01044  }
01045     }
01046     
01047     if (R != 0) {
01048  res = theChannel.sendMatrix(dataTag, cTag, *R);
01049  if (res < 0) {
01050    cerr << " Node::sendSelf() - failed to send R data\n";
01051    return res;
01052  }
01053     }    
01054     
01055     if (unbalLoad  != 0) {
01056  res = theChannel.sendVector(dbTag4, cTag, *unbalLoad); 
01057  if (res < 0) {
01058    cerr << " Node::sendSelf() - failed to send Load data\n";
01059    return res;
01060  }
01061     }
01062     
01063     // if get here succesfull
01064     return 0;
01065 }
01066 
01067 int 
01068 Node::recvSelf(int cTag, Channel &theChannel, 
01069         FEM_ObjectBroker &theBroker)
01070 {
01071     int res = 0;
01072     int dataTag = this->getDbTag();
01073 
01074     
01075     ID data(14);
01076     res = theChannel.recvID(dataTag, cTag, data);
01077     if (res < 0) {
01078       cerr << "Node::recvSelf() - failed to receive ID data\n";
01079       return res;
01080     }
01081 
01082     this->setTag(data(0));
01083     numberDOF = data(1);
01084     int numberCrd = data(7);
01085 
01086     dbTag1 = data(8);
01087     dbTag2 = data(9);
01088     dbTag3 = data(10);
01089     dbTag4 = data(11);
01090     
01091 
01092     // create a Vector to hold coordinates IF one needed
01093     if (Crd == 0)
01094       Crd = new Vector(numberCrd);
01095 
01096     // check we did not run out of memory
01097     if (Crd == 0) {
01098       g3ErrorHandler->warning("Node::recvSelf() - out of memory creating Coordinate vector\n");
01099       return -1;
01100     }
01101 
01102     if (theChannel.recvVector(dataTag, cTag, *Crd) < 0) {
01103       g3ErrorHandler->warning("Node::recvSelf() - failed to receive the Coordinate vector\n");
01104       return -2;
01105     }
01106  
01107     if (data(2) == 0) {
01108       // create the disp vectors if node is a total blank
01109       if (commitDisp == 0)
01110  this->createDisp();
01111 
01112       // recv the committed disp
01113       if (theChannel.recvVector(dbTag1, cTag, *commitDisp) < 0) {
01114  g3ErrorHandler->warning("Node::recvSelf - failed to receive Disp data\n");
01115  return res;
01116       }
01117 
01118       // set the trial quantities equal to committed
01119       for (int i=0; i<numberDOF; i++)
01120  disp[i] = disp[i+numberDOF];  // set trial equal commited
01121 
01122     } else if (commitDisp != 0) {
01123       // if going back to initial we will just zero the vectors
01124       commitDisp->Zero();
01125       trialDisp->Zero();
01126     }
01127       
01128     
01129     if (data(3) == 0) {
01130       // create the vel vectors if node is a total blank
01131       if (commitVel == 0) 
01132  this->createVel();
01133 
01134       // recv the committed vel
01135       if (theChannel.recvVector(dbTag2, cTag, *commitVel) < 0) {
01136  g3ErrorHandler->warning("Node::recvSelf - failed to receive Velocity data\n");
01137  return -3;
01138       }
01139 
01140       // set the trial quantity
01141       for (int i=0; i<numberDOF; i++)
01142  vel[i] = vel[i+numberDOF];  // set trial equal commited
01143     }
01144 
01145     if (data(4) == 0) {
01146       // create the vel vectors if node is a total blank
01147       if (commitAccel == 0) 
01148  this->createAccel();
01149 
01150       // recv the committed accel
01151       if (theChannel.recvVector(dbTag3, cTag, *commitAccel) < 0) {
01152  g3ErrorHandler->warning("Node::recvSelf - failed to receive Acceleration data\n");
01153  return -4;
01154       }
01155       
01156       // set the trial values
01157       for (int i=0; i<numberDOF; i++)
01158  accel[i] = accel[i+numberDOF];  // set trial equal commited
01159     }
01160     
01161     if (data(5) == 0) {
01162       // make some room and read in the vector
01163       if (mass == 0) {
01164  mass = new Matrix(numberDOF,numberDOF);
01165  if (mass == 0) {
01166    g3ErrorHandler->warning("Node::recvData -- ran out of memory\n");
01167    return -5;
01168  }
01169       }
01170       if (theChannel.recvMatrix(dataTag, cTag, *mass) < 0) {
01171  g3ErrorHandler->warning("Node::recvSelf() - failed to receive Mass data\n");
01172  return -6;
01173       }
01174     }            
01175     
01176     if (data(12) == 0) {
01177       // create a matrix for R
01178       int noCols = data(13);
01179       if (R == 0) {
01180  R = new Matrix(numberDOF, noCols);
01181  if (R == 0) {
01182    g3ErrorHandler->warning("Node::recvData -- ran out of memory\n");
01183    return -1;
01184  }
01185       }
01186       // now recv the R matrix
01187       if (theChannel.recvMatrix(dataTag, cTag, *R) < 0) {
01188  g3ErrorHandler->warning("Node::recvSelf() - failed to receive R data\n");
01189  return res;
01190       }
01191     }
01192 
01193     if (data(6) == 0) {
01194       // create a vector for the load
01195       if (unbalLoad == 0) {
01196  unbalLoad = new Vector(numberDOF);
01197  if (unbalLoad == 0) {
01198    g3ErrorHandler->warning("Node::recvData -- ran out of memory\n");
01199    return -10;
01200  }
01201       }
01202       if (theChannel.recvVector(dbTag4, cTag, *unbalLoad) < 0) {
01203  g3ErrorHandler->warning("Node::recvSelf() - failed to receive Load data\n");
01204  return res;
01205       }
01206     }        
01207 
01208     return 0;
01209 }
01210 
01211 
01212 
01213 void
01214 Node::Print(ostream &s, int flag)
01215 {
01216   if (flag == 0) { // print out everything
01217     s << "\n Node: " << this->getTag() << endl;
01218     s << "\tCoordinates  : " << *Crd;
01219     if (commitDisp != 0)         
01220  s << "\tcommitDisps: " << *commitDisp;
01221     if (commitVel != 0)     
01222  s << "\tVelocities   : " << *commitVel;
01223     if (commitAccel != 0)         
01224  s << "\tcommitAccels: " << *commitAccel;
01225     if (unbalLoad != 0)
01226       s << "\t unbalanced Load: " << *unbalLoad;
01227     if (mass != 0) 
01228  s << "\tMass : " << *mass;
01229     if (theEigenvectors != 0)
01230  s << "\t Eigenvectors: " << *theEigenvectors;
01231     if (theDOF_GroupPtr != 0)
01232       s << "\tID : " << theDOF_GroupPtr->getID();
01233     s << "\n"; 
01234   }
01235   else if (flag == 1) { // print out: nodeId displacements
01236     s << this->getTag() << "  " << *commitDisp;
01237   }
01238 }
01239   
01240 int
01241 Node::displaySelf(Renderer &theRenderer, int displayMode, float fact)
01242 {
01243 
01244   if (displayMode == 0)
01245     return 0;
01246 
01247   const Vector &theDisp = this->getDisp();
01248   Vector position(*Crd);
01249   for (int i=0; i<Crd->Size(); i++) 
01250     position(i) += theDisp(i)*fact; 
01251  
01252   if (displayMode == -1) { 
01253     // draw a text string containing tag
01254     static char theText[20];
01255     sprintf(theText,"%d",this->getTag());
01256     return theRenderer.drawText(position, theText, strlen(theText));
01257 
01258   } else if (displayMode > 0) 
01259     // draw a point - pixel size equals displayMode tag
01260     return theRenderer.drawPoint(position, 0.0, displayMode);
01261   
01262   return 0;
01263 }
01264 
01265 
01266 // createDisp(), createVel() and createAccel():
01267 // private methods to create the arrays to hold the disp, vel and acceleration
01268 // values and the Vector objects for the committed and trial quantaties.
01269 
01270 int
01271 Node::createDisp(void)
01272 {
01273   // trial , committed, incr = (committed-trial)
01274   disp = new double[4*numberDOF];
01275     
01276   if (disp == 0) {
01277     g3ErrorHandler->warning("WARNING - Node::createDisp() %s %d\n",
01278        "ran out of memory for array of size", 2*numberDOF);
01279     return -1;
01280   }
01281   for (int i=0; i<4*numberDOF; i++)
01282     disp[i] = 0.0;
01283     
01284   commitDisp = new Vector(&disp[numberDOF], numberDOF); 
01285   trialDisp = new Vector(disp, numberDOF);
01286   incrDisp = new Vector(&disp[2*numberDOF], numberDOF);
01287   incrDeltaDisp = new Vector(&disp[3*numberDOF], numberDOF);
01288   
01289   if (commitDisp == 0 || trialDisp == 0 || incrDisp == 0 || incrDeltaDisp == 0) {
01290     g3ErrorHandler->warning("WARNING - Node::createDisp() %s \n",
01291        "ran out of memory creating Vectors(double *,int)");
01292     return -2;
01293   }
01294     
01295   return 0;
01296 }
01297 
01298 
01299 int
01300 Node::createVel(void)
01301 {
01302     vel = new double[2*numberDOF];
01303     
01304     if (vel == 0) {
01305       g3ErrorHandler->warning("WARNING - Node::createVel() %s %d\n",
01306          "ran out of memory for array of size ",2*numberDOF);
01307  return -1;
01308     }
01309     for (int i=0; i<2*numberDOF; i++)
01310       vel[i] = 0.0;
01311     
01312     commitVel = new Vector(&vel[numberDOF], numberDOF); 
01313     trialVel = new Vector(vel, numberDOF);
01314     
01315     if (commitVel == 0 || trialVel == 0) {
01316       g3ErrorHandler->warning("WARNING - Node::createVel() %s\n",
01317          "ran out of memory creating Vectors(double *,int) ");
01318       return -2;
01319     }
01320     
01321     return 0;
01322 }
01323 
01324 int
01325 Node::createAccel(void)
01326 {
01327     accel = new double[2*numberDOF];
01328     
01329     if (accel == 0) {
01330       g3ErrorHandler->warning("WARNING - Node::createAccel() %s %d\n",
01331     "ran out of memory for array of size ",2*numberDOF);
01332  return -1;
01333     }
01334     for (int i=0; i<2*numberDOF; i++)
01335  accel[i] = 0.0;
01336     
01337     commitAccel = new Vector(&accel[numberDOF], numberDOF);
01338     trialAccel = new Vector(accel, numberDOF);
01339     
01340     if (commitAccel == 0 || trialAccel == 0) {
01341  g3ErrorHandler->warning("WARNING - Node::createAccel() %s\n",
01342     "ran out of memory creating Vectors(double *,int)");
01343  return -2;
01344     }
01345 
01346     return 0;
01347 }
01348 
01349 
Copyright Contact Us