PBowlLoading.cpp

Go to the documentation of this file.
00001 //===============================================================================
00002 //# COPYRIGHT (C): Woody's license (by BJ):
00003 //                 ``This    source  code is Copyrighted in
00004 //                 U.S.,  for  an  indefinite  period,  and anybody
00005 //                 caught  using it without our permission, will be
00006 //                 mighty good friends of ourn, cause we don't give
00007 //                 a  darn.  Hack it. Compile it. Debug it. Run it.
00008 //                 Yodel  it.  Enjoy it. We wrote it, that's all we
00009 //                 wanted to do.''
00010 //
00011 //# PROJECT:           Object Oriented Finite Element Program
00012 //# PURPOSE:           Plastic Bowl (aka Domain Reduction) implementation:
00013 //#                    This file contains the class definition
00014 //#                    for PBowlLoading.
00015 //#                    PBowlLoading is an subclass of loadPattern.
00016 //# CLASS:             PBowlLoading
00017 //#
00018 //# VERSION:           0.61803398874989 (golden section)
00019 //# LANGUAGE:          C++
00020 //# TARGET OS:         all...
00021 //# DESIGN:            Zhaohui Yang, Boris Jeremic
00022 //# PROGRAMMER(S):     Jinxiu Liao, Zhaohui Yang, Boris Jeremic
00023 //#
00024 //#
00025 //# DATE:              21Oct2002
00026 //# UPDATE HISTORY:    31Oct2002 fixed some memory leaks
00027 //#                    04Nov2002 changed the way plastic bowl elements are
00028 //#                     input.
00029 //#                    10Nov2002 Zeroing diagonal and out of diagaonal blocks
00030 //#                     for b<->e nodes
00031 //#                    13Nov2002 changes to split "b" and "e" nodes within
00032 //#                     the plastic bowl elements. Also, simple definition of
00033 //#                     of cubic bowl is now facilitated ...
00034 //#                    10Oct2003 split ifstream to three separate files as
00035 //#                     as it was giving some strange output on some systems...
00036 //#                    18May2004 put those files back (actually 6 of them, weird)
00037 //#                     Guanzhou, Matthias and Boris
00038 //#
00039 //===============================================================================
00040 
00041 // Purpose: This file contains the class definition for PBowlLoading.
00042 // PBowlLoading is an subclass of loadPattern.
00043 
00044 #include <PBowlLoading.h>
00045 #include <math.h>
00046 
00047 #include <iomanip>
00048 using std::ios;
00049 
00050 #include <fstream>
00051 using std::ifstream;
00052 
00053 PBowlLoading::PBowlLoading()
00054 :LoadPattern(0, PATTERN_TAG_PBowlLoading),
00055 PBowlElements(0),
00056 ExteriorNodes(0),
00057 BoundaryNodes(0),
00058 PBowlLoads(0),
00059 U(0),
00060 Udd(0)
00061 {
00062 
00063 }
00064 
00065 PBowlLoading::PBowlLoading(int tag,
00066                            const char *PBEfName,
00067                            const char *DispfName,
00068                            const char *AccefName,
00069                            double theTimeIncr,
00070                            double theFactor,
00071                            double xplus,
00072                            double xminus,
00073                            double yplus,
00074                            double yminus,
00075                            double zplus,
00076                            double zminus)
00077 :LoadPattern(tag,
00078              PATTERN_TAG_PBowlLoading),
00079              PBTimeIncr(theTimeIncr),
00080              cFactor(theFactor),
00081        xPlus(xplus),
00082        xMinus(xminus),
00083        yPlus(yplus),
00084        yMinus(yminus),
00085        zPlus(zplus),
00086        zMinus(zminus)
00087   {
00088     // determine the number of data points .. open file and count num entries
00089     int timeSteps1 = 0;
00090     int timeSteps2 = 0;
00091     int numDataPoints =0;
00092     double dataPoint;
00093     int eleID;
00094 
00095 
00096     ifstream theFileACC;
00097     ifstream theFileDIS;
00098     ifstream theFileELE;
00099 
00100   //--------------------------------
00101   //Input displacement data
00102   //--------------------------------
00103     theFileDIS.open(DispfName);
00104     if (theFileDIS.bad())
00105       {
00106         opserr << "WARNING - PBowlLoading::PBowlLoading()";
00107         opserr << " - could not open file " << DispfName << endln;
00108         exit(1);
00109       }
00110     else
00111       {
00112         //Input the number of time steps first
00113         theFileDIS >> timeSteps1;
00114     fprintf(stderr, "timesteps1= %d", timeSteps1);
00115         //Loop to count the number of data points
00116         while (theFileDIS >> dataPoint)
00117           numDataPoints++;
00118       }
00119     theFileDIS.close();
00120     UnumDataPoints = numDataPoints;
00121     thetimeSteps = timeSteps1;
00122     if ( timeSteps1 == 0)
00123       {
00124         opserr << "WARNING - PBowlLoading::PBowlLoading()";
00125         opserr << " - Time steps for displacement equal to zero... " << AccefName << endln;
00126         exit(0);
00127       }
00128 
00129   // create a vector and read in the data
00130     if (numDataPoints != 0) {
00131 
00132     // first open the file
00133     ifstream theFileDIS1;
00134     theFileDIS1.open(DispfName, ios::in);
00135     if (theFileDIS1.bad()) {
00136       opserr << "WARNING - PBowlLoading::PBowlLoading()";
00137       opserr << " - could not open file " << DispfName << endln;
00138      } else {
00139 
00140       // now create the vector
00141       if ( numDataPoints - thetimeSteps*(numDataPoints/thetimeSteps) != 0 ) {
00142          opserr << "WARNING - PBowlLoading::PBowlLoading()";
00143          opserr << " - Input data not sufficient...Patched with zeros " << DispfName << endln;
00144       }
00145       int cols = numDataPoints/thetimeSteps;
00146       U = new Matrix(cols, thetimeSteps);
00147 
00148       // ensure we did not run out of memory
00149       if (U == 0 || U->noRows() == 0 || U->noCols() == 0) {
00150          opserr << "PBowlLoading::PBowlLoading() - ran out of memory constructing";
00151          opserr << " a Matrix of size (cols*rows): " << cols << " * " << thetimeSteps << endln;
00152 
00153       if (U != 0)
00154          delete U;
00155          U = 0;
00156       }
00157 
00158       // read the data from the file
00159       else {
00160          theFileDIS1 >> timeSteps1;
00161          for (int t=0; t< thetimeSteps; t++)
00162            for  (int j=0;j<cols; j++) {
00163                theFileDIS1 >> dataPoint;
00164                (*U)(j, t) = dataPoint;
00165 //               fprintf(stdout, "U ( %d, %d ) = %12.6e \n", j, t, (*U)(j, t));
00166            }
00167       }
00168      }
00169 
00170       // finally close the file
00171       theFileDIS1.close();
00172   }
00173 
00174   //--------------------------------
00175   //Input acceleration data
00176   //--------------------------------
00177   theFileACC.open(AccefName);
00178   numDataPoints = 0;
00179 
00180   if (theFileACC.bad()) {
00181     opserr << "WARNING - PBowlLoading::PBowlLoading()";
00182     opserr << " - could not open file " << AccefName << endln;
00183     exit(2);
00184   } else {
00185     //Input the number of time steps first
00186     theFileACC >> timeSteps2;
00187     fprintf(stderr, "timesteps2= %d", timeSteps2);
00188     //Loop to count the number of data points
00189     while (theFileACC >> dataPoint)
00190       numDataPoints++;
00191   }
00192   theFileACC.close();
00193 
00194   UddnumDataPoints = numDataPoints;
00195   if ( timeSteps1 !=  timeSteps2) {
00196     opserr << "WARNING - PBowlLoading::PBowlLoading()";
00197     opserr << " - Time steps for displacement not equal to that for acceleration... " << AccefName << endln;
00198   }
00199 
00200 
00201   // create a vector and read in the data
00202   if (numDataPoints != 0) 
00203     {
00204 
00205       // first open the file
00206       ifstream theFileACC1;
00207       theFileACC1.open(AccefName, ios::in);
00208       if (theFileACC1.bad()) 
00209         {
00210           opserr << "WARNING - PBowlLoading::PBowlLoading()";
00211           opserr << " - could not open file " << AccefName << endln;
00212         } 
00213       else 
00214         {
00215       
00216           // now create the vector
00217           if ( numDataPoints - thetimeSteps*(numDataPoints/thetimeSteps) != 0 ) {
00218              opserr << "WARNING - PBowlLoading::PBowlLoading()";
00219              opserr << " - Input data not sufficient...Patched with zeros " << AccefName << endln;
00220           }
00221           int cols = numDataPoints/thetimeSteps;
00222           Udd = new Matrix(cols, thetimeSteps);
00223           
00224           // ensure we did not run out of memory
00225           if (Udd == 0 || Udd->noRows() == 0 || Udd->noCols() == 0) {
00226              opserr << "PBowlLoading::PBowlLoading() - ran out of memory constructing";
00227              opserr << " a Matrix of size (cols*rows): " << cols << " * " << thetimeSteps << endln;
00228           
00229           if (Udd != 0)
00230             delete Udd;
00231             Udd = 0;
00232           }
00233           
00234           // read the data from the file
00235           else 
00236             {
00237               theFileACC1 >> timeSteps2;
00238               for (int t=0; t< thetimeSteps; t++)
00239                 {
00240                   for  (int j=0;j<cols; j++) 
00241                     {
00242                       theFileACC1 >> dataPoint;
00243                       (*Udd)(j, t) = dataPoint;
00244 //                      fprintf(stdout, "Udd ( %d, %d ) = %12.6e \n", j, t, (*Udd)(j, t));
00245                     }
00246                 }
00247             }
00248         }
00249 
00250       // finally close the file
00251       theFileACC1.close();
00252     }
00253 
00254 
00255   
00256 
00257   //--------------------------------
00258   //Adding plastic bowl elements
00259   //from file to PBowlElements
00260   //--------------------------------
00261   theFileELE.open(PBEfName);
00262   numDataPoints = 0;
00263   int numPBE = 0;
00264 
00265   if (theFileELE.bad()) {
00266     opserr << "WARNING - PBowlLoading::PBowlLoading()";
00267     opserr << " - could not open file " << PBEfName << endln;
00268     exit(2);
00269   } else {
00270     //Input the number of Plastic Bowl elements
00271     theFileELE >> numPBE;
00272     //Loop to count the number of data points
00273     while (theFileELE >> eleID)
00274       numDataPoints++;
00275   }
00276   theFileELE.close();
00277   if ( numPBE !=  numDataPoints) {
00278     opserr << "WARNING - PBowlLoading::PBowlLoading()";
00279     opserr << " - Number of plastic bowl elements not equal to the number of elements provided... " << numDataPoints << numPBE << PBEfName << endln;
00280     exit(3);
00281   }
00282 
00283 
00284   // create a vector and read in the data
00285   if (numDataPoints != 0) {
00286 
00287     // first open the file
00288     ifstream theFileELE1;
00289     theFileELE1.open(PBEfName, ios::in);
00290     if (theFileELE1.bad()) {
00291       opserr << "WARNING - PBowlLoading::PBowlLoading()";
00292       opserr << " - could not open file " << PBEfName << endln;
00293     } else {
00294 
00295       // now create the vector
00296       PBowlElements = new ID(numPBE);
00297 
00298       // ensure we did not run out of memory
00299       if (PBowlElements == 0 || PBowlElements->Size() == 0 ) {
00300          opserr << "PBowlLoading::PBowlLoading() - ran out of memory constructing";
00301          opserr << " a ID of size: " << PBowlElements->Size()<< endln;
00302 
00303          if (PBowlElements != 0)
00304           delete PBowlElements;
00305          PBowlElements = 0;
00306       }
00307 
00308       // read the data from the file
00309       else {
00310         theFileELE1 >> numPBE;
00311         int i;
00312   for (i=0; i< numPBE; i++) {
00313               theFileELE1 >> eleID;
00314               (*PBowlElements)(i) = eleID;
00315         }
00316       }
00317 
00318       // finally close the file
00319       theFileELE1.close();
00320 
00321       //Check if read in correctly
00322 //BJ test
00323       opserr << "# of plastic bowl element: " << numPBE << endln;
00324      opserr <<  (*PBowlElements);
00325 //BJ test
00326     }
00327   }
00328 
00329   LoadComputed = false;
00330 }
00331 
00332 
00333 
00334 PBowlLoading::~PBowlLoading()
00335 {
00336   // invoke the destructor on all ground motions supplied
00337 
00338   if ( PBowlElements != 0)
00339     delete PBowlElements;
00340 
00341   if ( ExteriorNodes != 0)
00342     delete ExteriorNodes;
00343 
00344   if ( BoundaryNodes != 0)
00345     delete BoundaryNodes;
00346 
00347   if ( PBowlLoads != 0)
00348     delete PBowlLoads;
00349 
00350   if ( U != 0)
00351     delete U;
00352 
00353   if ( Udd != 0)
00354     delete Udd;
00355 
00356 }
00357 
00358 
00359 void
00360 PBowlLoading::setDomain(Domain *theDomain)
00361 {
00362   this->LoadPattern::setDomain(theDomain);
00363 
00364   // // now we go through and set all the node velocities to be vel0
00365   // if (vel0 != 0.0) {
00366   //   NodeIter &theNodes = theDomain->getNodes();
00367   //   Node *theNode;
00368   //   Vector newVel(1);
00369   //   int currentSize = 1;
00370   //   while ((theNode = theNodes()) != 0) {
00371   //     int numDOF = theNode->getNumberDOF();
00372   //     if (numDOF != currentSize)
00373   //   newVel.resize(numDOF);
00374   //
00375   //     newVel = theNode->getVel();
00376   //     newVel(theDof) = vel0;
00377   //     theNode->setTrialVel(newVel);
00378   //     theNode->commitState();
00379   //   }
00380   // }
00381 }
00382 
00383 
00384 void
00385 PBowlLoading::applyLoad(double time)
00386 {
00387 
00388   Domain *theDomain = this->getDomain();
00389   if (theDomain == 0)
00390     return;
00391 
00392   //Finding the all the nodes in the plastic bowl and sort it ascendingly
00393   if ( !LoadComputed )
00394      this->CompPBLoads();
00395 
00396   // see if quick return, i.e. no plastic bowl nodes or domain set
00397   int numBnodes = BoundaryNodes->Size();
00398   int numEnodes = ExteriorNodes->Size();
00399   if ( (numBnodes + numEnodes) == 0)
00400     return;
00401 
00402   //Apply loads on each boundary bowl nodes
00403   Node *theNode;
00404   int i;
00405   for (i=0; i<numBnodes; i++) {
00406     Vector load=this->getNodalLoad((*BoundaryNodes)[i], time);
00407     //Take care of the minus sign in the effective seismic force for boundary nodes
00408     load = load*(-1.0);
00409     theNode = theDomain->getNode( (*BoundaryNodes)[i] );
00410     theNode->addUnbalancedLoad(load);
00411   }
00412 
00413   //Apply loads on each exterior bowl nodes
00414   for (i=0; i<numEnodes; i++) {
00415     const Vector &load=this->getNodalLoad((*ExteriorNodes)[i], time);
00416     theNode = theDomain->getNode( (*ExteriorNodes)[i] );
00417     theNode->addUnbalancedLoad(load);
00418   }
00419 }
00420 
00421 int
00422 PBowlLoading::sendSelf(int commitTag, Channel &theChannel)
00423 {
00424   opserr << "PBowlLoading::sendSelf() - not yet implemented\n";
00425   return 0;
00426 }
00427 
00428 int
00429 PBowlLoading::recvSelf(int commitTag, Channel &theChannel,
00430        FEM_ObjectBroker &theBroker)
00431 {
00432   opserr << "PBowlLoading::recvSelf() - not yet implemented\n";
00433   return 0;
00434 }
00435 
00436 /* **********************************************************************************************
00437 int
00438 PBowlLoading::sendSelf(int commitTag, Channel &theChannel)
00439 {
00440   // first send the tag and info about the number of ground motions
00441   int myDbTag = this->getDbTag();
00442   ID theData(2);
00443   theData(0) = this->getTag();
00444   theData(1) = numMotions;
00445 
00446   if (theChannel.sendID(myDbTag, commitTag, theData) < 0) {
00447     g3ErrorHandler->warning("PBowlLoading::sendSelf - channel failed to send the initial ID");
00448     return -1;
00449   }
00450 
00451   // now for each motion we send it's classsss tag and dbtag
00452   ID theMotionsData(2*numMotions);
00453   for (int i=0; i<numMotions; i++) {
00454     theMotionsData[i] = theMotions[i]->getClassTag();
00455     int motionsDbTag = theMotions[i]->getDbTag();
00456     if (motionsDbTag == 0) {
00457       motionsDbTag = theChannel.getDbTag();
00458       theMotions[i]->setDbTag(motionsDbTag);
00459     }
00460     theMotionsData[i+numMotions] = motionsDbTag;
00461   }
00462 
00463   if (theChannel.sendID(myDbTag, commitTag, theMotionsData) < 0) {
00464     g3ErrorHandler->warning("PBowlLoading::sendSelf - channel failed to send the motions ID");
00465     return -1;
00466   }
00467 
00468   // now we send each motion
00469   for (int j=0; j<numMotions; j++)
00470     if (theMotions[j]->sendSelf(commitTag, theChannel) < 0) {
00471       g3ErrorHandler->warning("PBowlLoading::sendSelf - motion no: %d failed in sendSelf", j);
00472       return -1;
00473     }
00474 
00475   // if get here successfull
00476   return 0;
00477 }
00478 
00479 int
00480 PBowlLoading::recvSelf(int commitTag, Channel &theChannel,
00481        FEM_ObjectBroker &theBroker)
00482 {
00483   // first get the tag and info about the number of ground motions from the Channel
00484   int myDbTag = this->getDbTag();
00485   ID theData(2);
00486   if (theChannel.recvID(myDbTag, commitTag, theData) < 0) {
00487     g3ErrorHandler->warning("PBowlLoading::recvSelf - channel failed to recv the initial ID");
00488     return -1;
00489   }
00490 
00491   // set current tag
00492   this->setTag(theData(0));
00493 
00494   // now get info about each channel
00495   ID theMotionsData (2*theData(1));
00496   if (theChannel.recvID(myDbTag, commitTag, theMotionsData) < 0) {
00497     g3ErrorHandler->warning("PBowlLoading::recvSelf - channel failed to recv the motions ID");
00498     return -1;
00499   }
00500 
00501 
00502   if (numMotions != theData(1)) {
00503 
00504     //
00505     // we must delete the old motions and create new ones and then invoke recvSelf on these new ones
00506     //
00507 
00508     if (numMotions != 0) {
00509       for (int i=0; i<numMotions; i++)
00510   delete theMotions[i];
00511       delete [] theMotions;
00512     }
00513     numMotions = theData[1];
00514     theMotions = new (GroundMotion *)[numMotions];
00515     if (theMotions == 0) {
00516       g3ErrorHandler->warning("PBowlLoading::recvSelf - out of memory creating motion array of size %d\n", numMotions);
00517       numMotions = 0;
00518       return -1;
00519     }
00520 
00521     for (int i=0; i<numMotions; i++) {
00522       theMotions[i] = theBroker.getNewGroundMotion(theMotionsData[i]);
00523       if (theMotions[i] == 0) {
00524   g3ErrorHandler->warning("PBowlLoading::recvSelf - out of memory creating motion array of size %d\n", numMotions);
00525   numMotions = 0;
00526   return -1;
00527       }
00528       theMotions[i]->setDbTag(theMotionsData[i+numMotions]);
00529       if (theMotions[i]->recvSelf(commitTag, theChannel, theBroker) < 0) {
00530   g3ErrorHandler->warning("PBowlLoading::recvSelf - motion no: %d failed in recvSelf", i);
00531   numMotions = 0;
00532   return -1;
00533       }
00534     }
00535 
00536   } else {
00537 
00538     //
00539     // we invoke rrecvSelf on the motions, note if a motion not of correct class
00540     // we must invoke the destructor on the motion and create a new one of correct type
00541     //
00542 
00543     for (int i=0; i<numMotions; i++) {
00544       if (theMotions[i]->getClassTag() == theMotionsData[i]) {
00545   if (theMotions[i]->recvSelf(commitTag, theChannel, theBroker) < 0) {
00546     g3ErrorHandler->warning("PBowlLoading::recvSelf - motion no: %d failed in recvSelf", i);
00547     return -1;
00548   }
00549       } else {
00550   // motion not of correct type
00551   delete theMotions[i];
00552   theMotions[i] = theBroker.getNewGroundMotion(theMotionsData[i]);
00553   if (theMotions[i] == 0) {
00554     g3ErrorHandler->warning("PBowlLoading::recvSelf - out of memory creating motion array of size %d\n", numMotions);
00555     numMotions = 0;
00556     return -1;
00557   }
00558   theMotions[i]->setDbTag(theMotionsData[i+numMotions]);
00559   if (theMotions[i]->recvSelf(commitTag, theChannel, theBroker) < 0) {
00560     g3ErrorHandler->warning("PBowlLoading::recvSelf - motion no: %d failed in recvSelf", i);
00561     numMotions = 0;
00562     return -1;
00563   }
00564       }
00565     }
00566   }
00567 
00568   // if get here successfull
00569   return 0;
00570 }
00571 
00572 
00573 ***************************************************************************************** */
00574 
00575 void
00576 PBowlLoading::Print(OPS_Stream &s, int flag)
00577 {
00578   opserr << "PBowlLoading::Print() - not yet implemented\n";
00579 }
00580 
00581 
00582 
00583 // method to obtain a blank copy of the LoadPattern
00584 LoadPattern *
00585 PBowlLoading::getCopy(void)
00586 {
00587 
00588   opserr << "PBowlLoading::getCopy() - not yet implemented\n";
00589   return 0;
00590 }
00591 
00592 /* ****************************************************************************************
00593 // method to obtain a blank copy of the LoadPattern
00594 LoadPattern *
00595 PBowlLoading::getCopy(void)
00596 {
00597   PBowlLoading *theCopy = new PBowlLoading(0, 0);
00598   theCopy->setTag(this->getTag);
00599   theCopy->numMotions = numMotions;
00600   theCopy->theMotions = new (GroundMotion *)[numMotions];
00601   for (int i=0; i<numMotions; i++)
00602     theCopy->theMotions[i] = theMotions[i];
00603 
00604   return 0;
00605 }
00606 ***************************************************************************************** */
00607 
00608 // void
00609 // PBowlLoading::addPBElements(const ID &PBEle)
00610 // {
00611 //   // create a copy of the vector containg plastic bowl elements
00612 //   PBowlElements = new ID(PBEle);
00613 //   // ensure we did not run out of memory
00614 //   if (PBowlElements == 0 || PBowlElements->Size() == 0) {
00615 //     opserr << "PBowlLoading::addPBElements() - ran out of memory constructing";
00616 //     opserr << " a Vector of size: " <<  PBowlElements->Size() << endln;
00617 //     if (PBowlElements != 0)
00618 //       delete PBowlElements;
00619 //     PBowlElements = 0;
00620 //   }
00621 //
00622 // }
00623 
00624 
00625 void
00626 PBowlLoading::CompPBLoads()
00627 {
00628   //===========================================================
00629   // Finding all plastic bowl nodes, Joey Yang Oct. 18, 2002
00630   //===========================================================
00631   Domain *theDomain = this->getDomain();
00632 
00633   //Assume all the plastic bowl elements have the same number of nodes
00634   Element *theElement = theDomain->getElement( (*PBowlElements)(0) );
00635   int NIE = theElement->getNumExternalNodes();
00636 
00637   int max_bnode = PBowlElements->Size() * NIE;
00638   ID *Bowl_node = new ID(max_bnode);
00639   ID *Bound_node = new ID(max_bnode);
00640   ID NidesinFirstEle = theElement->getExternalNodes();
00641 
00642   int i, j, k, bi;
00643   //Inital node list from the first plastic bowl element
00644   for (i = 0; i<NIE; i++)
00645      (*Bowl_node)(i) = NidesinFirstEle(i);
00646 
00647   int no_bnode = NIE;
00648   int no_boundarynodes = 0, no_exteriornodes = 0;
00649   int Bowl_elem_nb = PBowlElements->Size();
00650   ID Temp;
00651 
00652   for ( i=1; i<Bowl_elem_nb; i++)
00653     {
00654       theElement = theDomain->getElement( (*PBowlElements)(i) );
00655       Temp = theElement->getExternalNodes();
00656       for ( j=0;j<NIE;j++)
00657         {
00658           for (k = 0; k< no_bnode; k++) 
00659             {
00660               if ( Temp(j) == (*Bowl_node)(k) )
00661               //opserr << Temp(j) << "  " << Bowl_node(k) << endln;
00662               break;
00663             } //endofIF
00664 
00665           //If no duplicate, add new node; otherwise, skip
00666           if ( k == no_bnode) 
00667             {
00668               (*Bowl_node)(no_bnode) = Temp(j);
00669               no_bnode ++;
00670             } //end of for (k=0...)
00671 
00672         }//end of for (j=0...)
00673 
00674     }
00675   //--Joey------------------------------------------------
00676 
00677   //BJ test
00678    //check the bowl nodes
00679    opserr << "\nCheck all plastic bowl nodes...\n";
00680    for (bi=0;bi<no_bnode;bi++)
00681       opserr<< (*Bowl_node)(bi) <<"  ";
00682    opserr<< endln << "# of pbowl nodes = " << no_bnode<<endln;
00683    //opserr<<"finish inputting  and organizing the Bowl_node array"<<endln;
00684   //BJ test
00685 
00686 
00687   //Find all nodes on the boundary Joey Yang & Boris Jeremic 11/06/02
00688   if ( (BoundaryNodes == 0) && ( (xPlus == xMinus) || (yPlus == yMinus) || (zPlus == zMinus) ) ) {
00689     opserr << "PBowlLoading::CompPBLoads() - Boundary node specification not correct..." << endln;
00690     exit(1);
00691   }
00692 
00693   no_boundarynodes = 0;
00694   for (i =0; i < no_bnode; i++) {
00695     Node *theNode = theDomain->getNode( (*Bowl_node)(i) );
00696     const Vector &coor = theNode->getCrds();
00697 
00698     //right face
00699     if ( (coor(0) == xPlus) && (coor(1) >= yMinus) && (coor(1) <= yPlus) && (coor(2) >= zMinus) && (coor(2) <= zPlus) ) {
00700        (*Bound_node)(no_boundarynodes) = (*Bowl_node)(i);
00701        no_boundarynodes++;
00702     }
00703     //left face
00704     else if ( (coor(0) == xMinus) && (coor(1) >= yMinus) && (coor(1) <= yPlus) && (coor(2) >= zMinus) && (coor(2) <= zPlus)) {
00705        (*Bound_node)(no_boundarynodes) = (*Bowl_node)(i);
00706        no_boundarynodes++;
00707     }
00708     //upper face
00709     else if ( (coor(1) == yPlus) && (coor(0) >= xMinus) && (coor(0) <= xPlus) && (coor(2) >= zMinus) && (coor(2) <= zPlus)) {
00710        (*Bound_node)(no_boundarynodes) = (*Bowl_node)(i);
00711        no_boundarynodes++;
00712     }
00713     //lower face
00714     else if ( (coor(1) == yMinus) && (coor(0) >= xMinus) && (coor(0) <= xPlus) && (coor(2) >= zMinus) && (coor(2) <= zPlus)) {
00715        (*Bound_node)(no_boundarynodes) = (*Bowl_node)(i);
00716        no_boundarynodes++;
00717     }
00718     //top face
00719     else if ( (coor(2) == zPlus) && (coor(0) >= xMinus) && (coor(0) <= xPlus) && (coor(1) >= yMinus) && (coor(1) <= yPlus)) {
00720        (*Bound_node)(no_boundarynodes) = (*Bowl_node)(i);
00721        no_boundarynodes++;
00722     }
00723     //bottom face
00724     else if ( (coor(2) == zMinus) && (coor(0) >= xMinus) && (coor(0) <= xPlus) && (coor(1) >= yMinus) && (coor(1) <= yPlus)) {
00725        (*Bound_node)(no_boundarynodes) = (*Bowl_node)(i);
00726        no_boundarynodes++;
00727     }
00728   }
00729 
00730   //Adding all boundary nodes on the plastic bowl
00731   BoundaryNodes = new ID(no_boundarynodes);
00732 
00733   if (BoundaryNodes == 0 || BoundaryNodes->Size() == 0) {
00734     opserr << "PBowlLoading::CompPBLoads() - ran out of memory constructing";
00735     opserr << " a Vector of size: " <<  BoundaryNodes->Size() << endln;
00736     if (BoundaryNodes != 0)
00737       delete BoundaryNodes;
00738     BoundaryNodes = 0;
00739   }
00740 
00741   no_exteriornodes = no_bnode;
00742   for (i =0; i < no_boundarynodes; i++) {
00743     (*BoundaryNodes)(i) = (*Bound_node)(i);
00744 
00745     //Sift out all the boundary nodes from Bowl_node
00746     for (j = 0; j < no_bnode; j++) {
00747        if ( (*Bowl_node)(j) == (*Bound_node)(i) ) {
00748           (*Bowl_node)(j) = 0; //zero this boundary nodes
00749     no_exteriornodes --;
00750        }
00751     }//end of sifting loop
00752   }//end of adding boundary node loop
00753 
00754   //Adding all exterior nodes on the plastic bowl
00755   ExteriorNodes = new ID(no_exteriornodes);
00756   if (ExteriorNodes == 0 || ExteriorNodes->Size() == 0) {
00757     opserr << "PBowlLoading::CompPBLoads() - ran out of memory constructing";
00758     opserr << " a Vector of size: " <<  ExteriorNodes->Size() << endln;
00759     if (ExteriorNodes != 0)
00760       delete ExteriorNodes;
00761     ExteriorNodes = 0;
00762   }
00763 
00764   j = 0;
00765   for (i =0; i < no_bnode; i++) {
00766     if ( (*Bowl_node)(i) != 0 ) {
00767        (*ExteriorNodes)(j) = (*Bowl_node)(i);
00768        j++;
00769     }
00770   }
00771 
00772   // BJ test
00773    //check the boundary bowl nodes
00774    opserr << "\nCheck all boundary bowl nodes...\n";
00775    for (bi = 0; bi < no_boundarynodes; bi++)
00776         opserr << (*BoundaryNodes)(bi) <<"  ";
00777    opserr<< endln << "# of boundary bowl nodes = " << no_boundarynodes << endln;
00778   
00779    //check the exterior bowl nodes
00780    opserr << "\nCheck all exterior bowl nodes...\n";
00781    for (bi = 0; bi < no_exteriornodes; bi++)
00782         opserr << (*ExteriorNodes)(bi) <<"  ";
00783    opserr<< endln << "# of exterior bowl nodes = " << no_exteriornodes << endln;
00784   
00785    opserr<<"finish inputting  and organizing the Bowl_node array"<<endln;
00786   // BJ test
00787 
00788 
00789   //===========================================================
00790   // Computing the equivalent(effective) forces for all plastic bowl nodes
00791   //===========================================================
00792 
00793   opserr<<"Computing the equivalent(effective) forces for all plastic bowl nodes"<<endln;
00794   int cols = Udd->noRows();
00795   //Matrix to hold the computed effective nodal forces for all plastic bowl DOFs and each time step
00796   Matrix *F = new Matrix(cols, thetimeSteps);
00797 
00798   //Assume all plastic bowl nodes have the same number of DOFs
00799   Node *theNode = theDomain->getNode((*BoundaryNodes)(0));
00800   int NDOF = theNode->getNumberDOF();
00801 
00802   Vector *Fm = new Vector(NIE*NDOF);
00803   Vector *Fk  = new Vector(NIE*NDOF);
00804   //Matrix *Ke= new Matrix(NIE*NDOF,NIE*NDOF);
00805   //Matrix *Me= new Matrix(NIE*NDOF,NIE*NDOF);
00806   Vector *u_e = new Vector(NIE*NDOF);
00807   Vector *udd_e = new Vector(NIE*NDOF);
00808 
00809 
00810   // intialize the F()
00811   for ( i=0;i<cols; i++)
00812       for ( j=0;j<thetimeSteps; j++)
00813          (*F)(i,j)=0;
00814 
00815   Element *theBowlElements;
00816 
00817   for ( i=0; i<Bowl_elem_nb; i++)
00818   {
00819    // get the Brick;
00820    theBowlElements = theDomain->getElement( (*PBowlElements)(i) );
00821    const ID &nd = theBowlElements->getExternalNodes();
00822 
00823    Matrix Me = theBowlElements ->getMass();
00824    Matrix Ke = theBowlElements ->getTangentStiff();
00825 
00826    //-------------------------------------------------------------------------
00827    //Zero diagonal block entries of boundary and exterior nodes, respectively
00828    //-------------------------------------------------------------------------
00829 
00830    //Find out the boundary and exterior nodes in this element
00831    ID *B_node = new ID(NIE);  //array to store the indices of all boundary nodes
00832    ID *E_node = new ID(NIE);  //array to store the indices of all exterior nodes
00833    int nB=0, nE=0;
00834    bool bdnode;
00835 
00836    for ( int ii = 0; ii < NIE; ii++) {
00837     //Check if nd(ii) is boundary node or not
00838     bdnode = false;
00839     for (int id = 0; id < no_boundarynodes; id++) {
00840        if ( nd(ii) == (*BoundaryNodes)(id) ) {
00841          bdnode = true;
00842           break;
00843        }
00844     }
00845 
00846     if ( bdnode ) {
00847        (*B_node)(nB) = ii;
00848        nB ++;
00849     }
00850     else {
00851        (*E_node)(nE) = ii;
00852        nE ++;
00853     }
00854    }
00855 
00856    //BJ test
00857     opserr << "B nodes: " << nB << " " << *B_node;
00858     opserr << "E nodes: " << nE << " " << *E_node;
00859 
00860     opserr << " ...Me before  " << Me;
00861    //BJ test
00862    //Zero out the diagonal block of Boundary nodes
00863    int m;
00864    for (m = 0; m < nB; m++)
00865      for (int n = 0; n < nB; n++)
00866       for (int d = 0; d < NDOF; d++)
00867         for (int e= 0; e < NDOF; e++) {
00868           Me( (*B_node)(m)*NDOF+d, (*B_node)(n)*NDOF+e ) = 0.0;
00869           Ke( (*B_node)(m)*NDOF+d, (*B_node)(n)*NDOF+e ) = 0.0;
00870         }
00871 
00872    //Zero out the diagonal block of Exterior nodes
00873    for (m = 0; m < nE; m++)
00874      for (int n = 0; n < nE; n++)
00875       for (int d = 0; d < NDOF; d++)
00876         for (int e= 0; e < NDOF; e++) {
00877           Me( (*E_node)(m)*NDOF+d, (*E_node)(n)*NDOF+e ) = 0.0;
00878           Ke( (*E_node)(m)*NDOF+d, (*E_node)(n)*NDOF+e ) = 0.0;
00879         }
00880 
00881    //BJ test
00882     opserr << " ...Me after  " << Me;
00883     opserr << " ...Ke after  " << Ke;
00884    //BJ test
00885 
00886    //   get the u and u_dotdot for this element
00887    for ( int t=0;t<thetimeSteps; t++)
00888    {
00889      //opserr << "element: " << i << "" << " Time step: " << t << endln;
00890      for (int j=0;j<NIE;j++)  //BJ make it into # of nodes per element (2D or 3D...)
00891      {
00892        for (int d=0;d<NDOF;d++)
00893        {
00894            (*u_e)(j*NDOF+d)    =   (*U)( nd(j)*NDOF-NDOF+d,t);
00895          (*udd_e)(j*NDOF+d)    = (*Udd)( nd(j)*NDOF-NDOF+d,t);
00896        }
00897      }
00898 
00899      Fm->addMatrixVector(0.0, Me, (*udd_e), 1.0);
00900      Fk->addMatrixVector(0.0, Ke, (*u_e), 1.0);
00901 
00902      for (int k=0;k<NIE; k++)
00903         for (int d=0;d<NDOF;d++) {
00904             (*F)( nd(k)*NDOF-NDOF+d,t) = (*F)( nd(k)*NDOF-NDOF+d,t) + (*Fk)(k*NDOF+d) + (*Fm)(k*NDOF+d);
00905   }
00906 
00907    } //end for timestep
00908 
00909   }  // end for bowl element
00910 
00911   PBowlLoads = new Matrix(*F);
00912 
00913   // ensure we did not run out of memory
00914   if (PBowlLoads->noRows() == 0 || PBowlLoads->noCols() == 0 ) {
00915     opserr << "PBowlLoading::PBowlLoads() - ran out of memory";
00916     opserr << " a Matrix of size: " <<  PBowlLoads->noRows() << " * " << PBowlLoads->noCols() << endln;
00917   }
00918 
00919 //BJ test
00920 
00921  opserr<<"\nFinish calculating the forces..." << endln << endln;
00922 //BJ test
00923   LoadComputed = true;
00924 
00925   delete Fm;
00926   delete Fk;
00927   delete u_e;
00928   delete udd_e;
00929   delete F;
00930 
00931 }
00932 
00933 
00934 const Vector &
00935 PBowlLoading::getNodalLoad(int nodeTag, double time)
00936 {
00937   Vector *dummy = new Vector(0);
00938   //Get the node
00939   Domain *theDomain = this->getDomain();
00940   Node *theNode = theDomain->getNode(nodeTag);
00941   if (theNode == 0) 
00942     {
00943        opserr << "PBowlLoading::getNodalLoad() - no nodes associtated to the nodeTag " << nodeTag << "\n";
00944        return ( *dummy );
00945     }
00946 
00947   delete dummy;
00948 
00949   //Create the nodal load vector accoding to the DOFs the node has
00950   int numDOF = theNode->getNumberDOF();
00951   Vector *nodalLoad = new Vector(numDOF);
00952 
00953 
00954   //Get the nodal loads associated to the nodeTag
00955   // check for a quick return
00956   if (time < 0.0 || PBowlLoads == 0)
00957     return (*nodalLoad);
00958 
00959   // determine indexes into the data array whose boundary holds the time
00960   double incr = time/PBTimeIncr;
00961   int incr1 = (int) floor(incr)-1;
00962   int incr2 = incr1 + 1;
00963 
00964   double value1=0;
00965   double value2=0;
00966 
00967   int i;
00968   if ( incr2 == thetimeSteps ) {
00969     for (i = 0; i < numDOF; i++)
00970        (*nodalLoad)(i) = (*PBowlLoads)(i, incr1);
00971   }
00972 
00973   //If beyond time step, return 0 loads
00974   else if (incr2 > thetimeSteps ) {
00975       //test if ( nodeTag == 109)
00976       //test    opserr << "Time = " << time << " Node # " << nodeTag  << " " << (*nodalLoad) << endln;
00977       return (*nodalLoad);
00978   }
00979 
00980   //If within time step, return interpolated values
00981   else {
00982     for (i = 0; i < numDOF; i++){
00983        value1 = (*PBowlLoads)(numDOF*(nodeTag-1)+i, incr1);
00984        value2 = (*PBowlLoads)(numDOF*(nodeTag-1)+i, incr2);
00985        (*nodalLoad)(i) = cFactor*(value1 + (value2-value1)*(time/PBTimeIncr - incr2));
00986     }
00987   }
00988 
00989   //test if ( nodeTag == 109) {
00990   //test    opserr << "Time = " << time << " Node # " << nodeTag  << " " << (*nodalLoad) << endln;
00991   //test }
00992 
00993   return (*nodalLoad);
00994 
00995 }
00996 

Generated on Mon Oct 23 15:05:02 2006 for OpenSees by doxygen 1.5.0