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

GenericSectionNd.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.1.1.1 $
00022 // $Date: 2000/09/15 08:23:22 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/material/section/GenericSectionNd.cpp,v $
00024                                                                         
00025                                                                         
00026 // File: ~/material/GenericSectionNd.C
00027 //
00028 // Written: MHS 
00029 // Created: Apr 2000
00030 // Revision: A
00031 //
00032 // Description: This file contains the class implementation for GenericSectionNd.
00033 //
00034 // What: "@(#) GenericSectionNd.C, revA"
00035 
00036 #include <GenericSectionNd.h>
00037 #include <NDMaterial.h>
00038 #include <Channel.h>
00039 #include <FEM_ObjectBroker.h>
00040 #include <Information.h>
00041 
00042 #include <Matrix.h>
00043 #include <Vector.h>
00044 #include <ID.h>
00045 
00046 #include <G3Globals.h>
00047 #include <classTags.h>
00048 
00049 #include <string.h>
00050 
00051 GenericSectionNd::GenericSectionNd(int tag, NDMaterial &m, const ID &mCode)
00052 :SectionForceDeformation(tag,SEC_TAG_GenericNd),
00053  theModel(0), code(0), otherDbTag(0)
00054 {
00055     theModel = m.getCopy();
00056 
00057     if (theModel == 0) {
00058   g3ErrorHandler->fatal("%s -- failed to get copy of material model",
00059    "GenericSectionNd::GenericSectionNd");
00060     }
00061 
00062  order = theModel->getOrder();
00063 
00064  code = new ID(mCode);
00065 
00066  if (code == 0) {
00067   g3ErrorHandler->fatal("%s -- failed to allocate section ID",
00068    "GenericSectionNd::GenericSectionNd");
00069  }
00070 
00071     if (order != code->Size()) {
00072   g3ErrorHandler->warning("%s -- code size does not match order of material model",
00073    "GenericSectionNd::GenericSectionNd");
00074     }
00075 }
00076 
00077 GenericSectionNd::GenericSectionNd()
00078 :SectionForceDeformation(0,SEC_TAG_GenericNd), 
00079   theModel(0), code(0), order(0), otherDbTag(0)
00080 {
00081     
00082 }
00083 
00084 GenericSectionNd::~GenericSectionNd()
00085 {
00086   if (theModel)
00087     delete theModel;
00088 
00089   if (code)
00090     delete code;
00091 }
00092 
00093 int
00094 GenericSectionNd::setTrialSectionDeformation (const Vector& def)
00095 {
00096     return theModel->setTrialStrain(def);
00097 }
00098 
00099 const Vector&
00100 GenericSectionNd::getSectionDeformation ()
00101 {
00102     return theModel->getStrain();
00103 }
00104 
00105 const Vector&
00106 GenericSectionNd::getStressResultant ()
00107 {
00108     return theModel->getStress();
00109 }
00110 
00111 const Matrix&
00112 GenericSectionNd::getSectionTangent ()
00113 {
00114     return theModel->getTangent();
00115 }
00116 
00117 int
00118 GenericSectionNd::commitState ()
00119 {
00120     return theModel->commitState();
00121 }
00122 
00123 int
00124 GenericSectionNd::revertToLastCommit ()
00125 {
00126     return theModel->revertToLastCommit();
00127 }
00128 
00129 int
00130 GenericSectionNd::revertToStart ()
00131 {
00132     return theModel->revertToStart();
00133 }
00134 
00135 const ID&
00136 GenericSectionNd::getType () const
00137 {
00138     return *code;
00139 }
00140 
00141 int
00142 GenericSectionNd::getOrder () const
00143 {
00144     return order;
00145 }
00146 
00147 SectionForceDeformation*
00148 GenericSectionNd::getCopy ()
00149 {
00150     GenericSectionNd *theCopy = new GenericSectionNd (this->getTag(),
00151             *theModel, *code);
00152 
00153  theCopy->otherDbTag = otherDbTag;
00154 
00155     return theCopy;
00156 }
00157 
00158 int
00159 GenericSectionNd::sendSelf(int cTag, Channel &theChannel)
00160 {
00161     int res = 0;
00162 
00163  // Need otherDbTag since code ID and data ID may be the same size
00164     if (otherDbTag == 0) 
00165   otherDbTag = theChannel.getDbTag();
00166 
00167  static ID data(5);
00168 
00169  data(0) = this->getTag();
00170  data(1) = order;
00171  data(2) = otherDbTag;
00172  data(3) = theModel->getClassTag();
00173 
00174  int dbTag = theModel->getDbTag();
00175 
00176  if (dbTag == 0) {
00177   dbTag = theChannel.getDbTag();
00178   if (dbTag != 0)
00179    theModel->setDbTag(dbTag);
00180  }
00181 
00182  data(4) = dbTag;
00183 
00184  // Send the ID vector
00185  res += theChannel.sendID(this->getDbTag(), cTag, data);
00186  if (res < 0) {
00187   g3ErrorHandler->warning("%s -- could not send data ID",
00188    "GenericSectionNd::sendSelf");
00189   return res;
00190  }
00191     
00192  // Send the section code
00193  res += theChannel.sendID(otherDbTag, cTag, *code);
00194  if (res < 0) {
00195   g3ErrorHandler->warning("%s -- could not send code ID",
00196    "GenericSectionNd::sendSelf");
00197   return res;
00198  }
00199 
00200  // Ask the NDMaterial to send itself
00201  res += theModel->sendSelf(cTag, theChannel);
00202  if (res < 0) {
00203   g3ErrorHandler->warning("%s -- could not send NDMaterial",
00204    "GenericSectionNd::sendSelf");
00205   return res;
00206  }
00207 
00208     return res;
00209 }
00210 
00211 int
00212 GenericSectionNd::recvSelf(int cTag, Channel &theChannel,
00213       FEM_ObjectBroker &theBroker)
00214 {
00215  int res = 0;
00216 
00217     static ID data(5);
00218 
00219  // Receive the data ID
00220     res += theChannel.recvID(this->getDbTag(), cTag, data);
00221  if (res < 0) {
00222   g3ErrorHandler->warning("%s -- could not receive data ID",
00223    "GenericSectionNd::recvSelf");
00224   return res;
00225  }
00226 
00227  this->setTag(data(0));
00228  order = data(1);
00229  otherDbTag = data(2);
00230 
00231  // Check if section ID code is null or wrong size, reallocate if so
00232  if (code == 0)
00233   code = new ID(order);
00234  else if (code->Size() != order) {
00235   delete code;
00236   code = new ID(order);
00237  }
00238  if (code == 0) {
00239   g3ErrorHandler->warning("%s -- could not allocate new code ID",
00240    "GenericSectionNd::recvSelf");
00241   return -1;
00242  }
00243 
00244  // Receive the code ID
00245     res += theChannel.recvID(otherDbTag, cTag, *code);
00246  if (res < 0) {
00247   g3ErrorHandler->warning("%s -- could not receive code ID",
00248    "GenericSectionNd::recvSelf");
00249   return res;
00250  }
00251 
00252  int classTag = data(3);
00253 
00254  // Check if the material is null; if so, get a new one
00255  if (theModel == 0)
00256   theModel = theBroker.getNewNDMaterial(classTag);
00257 
00258  // Check that the material is of the right type; if not, delete
00259  // the current one and get a new one of the right type
00260  else if (theModel->getClassTag() != classTag) {
00261   delete theModel;
00262   theModel = theBroker.getNewNDMaterial(classTag);
00263  }
00264 
00265  // Check if either allocation failed
00266  if (theModel == 0) {
00267   g3ErrorHandler->warning("%s -- could not get an NDMaterial",
00268    "GenericSectionNd::recvSelf");
00269   return -1;
00270  }
00271 
00272  // Now, receive the material
00273  theModel->setDbTag(data(4));
00274  res += theModel->recvSelf(cTag, theChannel, theBroker);
00275  if (res < 0) {
00276   g3ErrorHandler->warning("%s -- could not receive NDMaterial",
00277    "GenericSectionNd::recvSelf");
00278   return res;
00279  }
00280 
00281     return res;
00282 }
00283 
00284 void
00285 GenericSectionNd::Print (ostream &s, int flag)
00286 {
00287     s << "Generic Section Nd, tag: " << this->getTag() << endl;
00288     s << "\tsection code: " << code << endl;
00289 }
Copyright Contact Us