MinMaxMaterial.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: 2003/04/02 22:02:42 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/material/uniaxial/MinMaxMaterial.cpp,v $
00024 
00025 // Written: MHS
00026 // Created: Aug 2001
00027 //
00028 // Description: This file contains the class definition for 
00029 // MinMaxMaterial.  MinMaxMaterial wraps a UniaxialMaterial
00030 // and imposes min and max strain limits.
00031 
00032 #include <stdlib.h>
00033 
00034 #include <MinMaxMaterial.h>
00035 #include <ID.h>
00036 #include <Channel.h>
00037 #include <FEM_ObjectBroker.h>
00038 
00039 #include <OPS_Globals.h>
00040 
00041 MinMaxMaterial::MinMaxMaterial(int tag, UniaxialMaterial &material,
00042                                double min, double max)
00043   :UniaxialMaterial(tag,MAT_TAG_MinMax), theMaterial(0),
00044    minStrain(min), maxStrain(max), Tfailed(false), Cfailed(false)
00045 {
00046   theMaterial = material.getCopy();
00047 
00048   if (theMaterial == 0) {
00049     opserr <<  "MinMaxMaterial::MinMaxMaterial -- failed to get copy of material\n";
00050     exit(-1);
00051   }
00052 }
00053 
00054 MinMaxMaterial::MinMaxMaterial()
00055   :UniaxialMaterial(0,MAT_TAG_MinMax), theMaterial(0),
00056    minStrain(0.0), maxStrain(0.0), Tfailed(false), Cfailed(false)
00057 {
00058 
00059 }
00060 
00061 MinMaxMaterial::~MinMaxMaterial()
00062 {
00063   if (theMaterial)
00064     delete theMaterial;
00065 }
00066 
00067 int 
00068 MinMaxMaterial::setTrialStrain(double strain, double strainRate)
00069 {
00070   if (Cfailed)
00071     return 0;
00072   
00073   if (strain >= maxStrain || strain <= minStrain) {
00074     Tfailed = true;
00075     return 0;
00076   }
00077   else {
00078     Tfailed = false;
00079     return theMaterial->setTrialStrain(strain, strainRate);
00080   }
00081 }
00082 
00083 double 
00084 MinMaxMaterial::getStress(void)
00085 {
00086   if (Tfailed)
00087     return 0.0;
00088   else
00089     return theMaterial->getStress();
00090 }
00091 
00092 double 
00093 MinMaxMaterial::getTangent(void)
00094 {
00095   if (Tfailed)
00096     //return 0.0;
00097     return 1.0e-8*theMaterial->getInitialTangent();
00098   else
00099     return theMaterial->getTangent();
00100 }
00101 
00102 double 
00103 MinMaxMaterial::getDampTangent(void)
00104 {
00105   if (Tfailed)
00106     return 0.0;
00107   else
00108     return theMaterial->getDampTangent();
00109 }
00110 
00111 
00112 
00113 double 
00114 MinMaxMaterial::getStrain(void)
00115 {
00116   return theMaterial->getStrain();
00117 }
00118 
00119 double 
00120 MinMaxMaterial::getStrainRate(void)
00121 {
00122   return theMaterial->getStrainRate();
00123 }
00124 
00125 int 
00126 MinMaxMaterial::commitState(void)
00127 {       
00128   Cfailed = Tfailed;
00129 
00130   // Check if failed at current step
00131   if (Tfailed)
00132     return 0;
00133   else
00134     return theMaterial->commitState();
00135 }
00136 
00137 int 
00138 MinMaxMaterial::revertToLastCommit(void)
00139 {
00140   // Check if failed at last step
00141   if (Cfailed)
00142     return 0;
00143   else
00144     return theMaterial->revertToLastCommit();
00145 }
00146 
00147 int 
00148 MinMaxMaterial::revertToStart(void)
00149 {
00150   Cfailed = false;
00151   Tfailed = false;
00152   
00153   return theMaterial->revertToStart();
00154 }
00155 
00156 UniaxialMaterial *
00157 MinMaxMaterial::getCopy(void)
00158 {
00159   MinMaxMaterial *theCopy = 
00160     new MinMaxMaterial(this->getTag(), *theMaterial, minStrain, maxStrain);
00161         
00162   theCopy->Cfailed = Cfailed;
00163   theCopy->Tfailed = Tfailed;
00164   
00165   return theCopy;
00166 }
00167 
00168 int 
00169 MinMaxMaterial::sendSelf(int cTag, Channel &theChannel)
00170 {
00171   int dbTag = this->getDbTag();
00172 
00173   static ID dataID(3);
00174   dataID(0) = this->getTag();
00175   dataID(1) = theMaterial->getClassTag();
00176   int matDbTag = theMaterial->getDbTag();
00177   if ( matDbTag == 0) {
00178     matDbTag = theChannel.getDbTag();
00179     theMaterial->setDbTag(matDbTag);
00180   }
00181   dataID(2) = matDbTag;
00182   if (theChannel.sendID(dbTag, cTag, dataID) < 0) {
00183     opserr << "MinMaxMaterial::sendSelf() - failed to send the ID\n";
00184     return -1;
00185   }
00186 
00187   static Vector dataVec(3);
00188   dataVec(0) = minStrain;
00189   dataVec(1) = maxStrain;
00190   if (Cfailed == true)
00191     dataVec(2) = 1.0;
00192   else
00193     dataVec(2) = 0.0;
00194 
00195   if (theChannel.sendVector(dbTag, cTag, dataVec) < 0) {
00196     opserr << "MinMaxMaterial::sendSelf() - failed to send the Vector\n";
00197     return -2;
00198   }
00199 
00200   if (theMaterial->sendSelf(cTag, theChannel) < 0) {
00201     opserr << "MinMaxMaterial::sendSelf() - failed to send the Material\n";
00202     return -3;
00203   }
00204 
00205   return 0;
00206 }
00207 
00208 int 
00209 MinMaxMaterial::recvSelf(int cTag, Channel &theChannel, 
00210                          FEM_ObjectBroker &theBroker)
00211 {
00212   int dbTag = this->getDbTag();
00213 
00214   static ID dataID(3);
00215   if (theChannel.recvID(dbTag, cTag, dataID) < 0) {
00216     opserr << "MinMaxMaterial::recvSelf() - failed to get the ID\n";
00217     return -1;
00218   }
00219   this->setTag(int(dataID(0)));
00220 
00221   // as no way to change material, don't have to check classTag of the material 
00222   if (theMaterial == 0) {
00223     int matClassTag = int(dataID(1));
00224     theMaterial = theBroker.getNewUniaxialMaterial(matClassTag);
00225     if (theMaterial == 0) {
00226       opserr << "MinMaxMaterial::recvSelf() - failed to create Material with classTag " 
00227            << dataID(0) << endln;
00228       return -2;
00229     }
00230   }
00231   theMaterial->setDbTag(dataID(2));
00232 
00233   static Vector dataVec(3);
00234   if (theChannel.recvVector(dbTag, cTag, dataVec) < 0) {
00235     opserr << "MinMaxMaterial::recvSelf() - failed to get the Vector\n";
00236     return -3;
00237   }
00238 
00239   minStrain = dataVec(0);
00240   maxStrain = dataVec(1);
00241   
00242   if (dataVec(2) == 1.0)
00243     Cfailed = true;
00244   else
00245     Cfailed = false;
00246 
00247   Tfailed = Cfailed;
00248 
00249   if (theMaterial->recvSelf(cTag, theChannel, theBroker) < 0) {
00250     opserr << "MinMaxMaterial::recvSelf() - failed to get the Material\n";
00251     return -4;
00252   }
00253   return 0;
00254 }
00255 
00256 void 
00257 MinMaxMaterial::Print(OPS_Stream &s, int flag)
00258 {
00259   s << "MinMaxMaterial tag: " << this->getTag() << endln;
00260   s << "\tMaterial: " << theMaterial->getTag() << endln;
00261   s << "\tMin strain: " << minStrain << endln;
00262   s << "\tMax strain: " << maxStrain << endln;
00263 }

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