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

ParallelMaterial.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/uniaxial/ParallelMaterial.cpp,v $
00024                                                                         
00025                                                                         
00026 // File: ~/material/ParallelModel.C
00027 //
00028 // Written: fmk 
00029 // Created: 07/98
00030 // Revision: A
00031 //
00032 // Description: This file contains the class definition for 
00033 // ParallelModel. ParallelModel is an aggregation
00034 // of UniaxialMaterial objects all considered acting in parallel.
00035 //
00036 // What: "@(#) ParallelModel.C, revA"
00037 
00038 #include <ParallelMaterial.h>
00039 #include <ID.h>
00040 #include <Vector.h>
00041 #include <Channel.h>
00042 #include <FEM_ObjectBroker.h>
00043 #include <stdlib.h>
00044 
00045 
00046 ParallelMaterial::ParallelMaterial(
00047      int tag, 
00048      int num, 
00049      UniaxialMaterial ** theMaterialModels,
00050                                  double min, double max)
00051 :UniaxialMaterial(tag,MAT_TAG_ParallelMaterial),
00052  trialStrain(0.0), numMaterials(num), otherDbTag(0), theModels(0), 
00053  epsmin(min), epsmax(max), Cfailed(0), Tfailed(0)
00054 {
00055     // create an array (theModels) to store copies of the MaterialModels
00056     theModels = new UniaxialMaterial *[num];
00057 
00058     if (theModels == 0) {
00059  cerr << "FATAL ParallelMaterial::ParallelMaterial() ";
00060  cerr << " ran out of memory for array of size: " << num << "\n";
00061  exit(-1);
00062     }
00063 
00064     // into the newly created array store a ponter to a copy
00065     // of the UniaxialMaterial stored in theMaterialModels
00066     for (int i=0; i<num; i++) {
00067  theModels[i] = theMaterialModels[i]->getCopy();
00068     }
00069 }
00070 
00071 
00072 
00073 // this constructor is used for a ParallelMaterailModel object that
00074 // needs to be constructed in a remote actor process. recvSelf() needs
00075 // to be called on this object
00076 ParallelMaterial::ParallelMaterial()
00077 :UniaxialMaterial(0,MAT_TAG_ParallelMaterial),
00078  trialStrain(0.0), numMaterials(0), otherDbTag(0), theModels(0), 
00079  epsmin(NEG_INF_STRAIN), epsmax(POS_INF_STRAIN), Cfailed(0), Tfailed(0)
00080 {
00081 
00082 }
00083 
00084 
00085 ParallelMaterial::~ParallelMaterial()
00086 {
00087     // invoke the destructor on each MaterialModel object
00088     for (int i=0; i<numMaterials; i++)
00089  delete theModels[i];
00090 
00091     // now we can delete the array
00092     if (theModels != 0) // just in case blank constructor called and no recvSelf()
00093  delete [] theModels;
00094 }
00095 
00096 
00097 
00098 int 
00099 ParallelMaterial::setTrialStrain(double strain, double strainRate)
00100 {
00101     // set the trialStrain and the trialStrain in each of the
00102     // local MaterialModel objects 
00103  Tfailed = Cfailed;
00104     trialStrain = strain;
00105  trialStrainRate = strainRate;
00106 
00107     if (trialStrain < epsmin || trialStrain > epsmax)
00108         Tfailed = 1;
00109 
00110     if (!Tfailed) {
00111         for (int i=0; i<numMaterials; i++)
00112      theModels[i]->setTrialStrain(strain, strainRate);
00113     }
00114 
00115     return 0;
00116 }
00117 
00118 
00119 double 
00120 ParallelMaterial::getStrain(void)
00121 {
00122     return trialStrain;
00123 }
00124 
00125 double 
00126 ParallelMaterial::getStrainRate(void)
00127 {
00128     return trialStrainRate;
00129 }
00130 
00131 double 
00132 ParallelMaterial::getStress(void)
00133 {
00134     // get the stress = sum of stress in all local MaterialModel objects
00135     double stress = 0.0;
00136     if (!Tfailed) {
00137         for (int i=0; i<numMaterials; i++)
00138      stress +=theModels[i]->getStress();
00139     }
00140 
00141     return stress;
00142 }
00143 
00144 
00145 
00146 double 
00147 ParallelMaterial::getTangent(void)
00148 {
00149     // get the tangent = sum of tangents in all local MaterialModel objects    
00150     double E = 0.0;
00151     if (!Tfailed) {
00152         for (int i=0; i<numMaterials; i++)
00153      E +=theModels[i]->getTangent();    
00154     }
00155 
00156     return E;
00157 }
00158 
00159 double 
00160 ParallelMaterial::getDampTangent(void)
00161 {
00162     // get the damp tangent = sum of damp tangents in all local MaterialModel objects    
00163     double eta = 0.0;
00164     if (!Tfailed) {
00165         for (int i=0; i<numMaterials; i++)
00166      eta +=theModels[i]->getDampTangent();    
00167     }
00168 
00169     return eta;
00170 }
00171 
00172 double ParallelMaterial::getSecant ()
00173 {
00174  // get the secant = sum of secants in all local MaterialModel objects    
00175     double S = 0.0;
00176     if (!Tfailed) {
00177         for (int i=0; i<numMaterials; i++)
00178      S +=theModels[i]->getSecant();    
00179     }
00180 
00181     return S;
00182 }
00183 
00184 int 
00185 ParallelMaterial::commitState(void)
00186 {
00187     Cfailed = Tfailed;
00188 
00189     // invoke commitState() on each of local MaterialModel objects
00190     for (int i=0; i<numMaterials; i++)
00191  if (theModels[i]->commitState() != 0) {
00192      cerr << "WARNING ParallelMaterial::commitState() ";
00193      cerr << "MaterialModel failed to commitState():" ;
00194      theModels[i]->Print(cerr);
00195  }
00196     
00197     return 0;    
00198 }
00199 
00200 int 
00201 ParallelMaterial::revertToLastCommit(void)
00202 {
00203     Tfailed = Cfailed;
00204 
00205     // invoke commitState() on each of local MaterialModel objects
00206     for (int i=0; i<numMaterials; i++)
00207  if (theModels[i]->revertToLastCommit() != 0) {
00208      cerr << "WARNING ParallelMaterial::revertToLastCommit() ";
00209      cerr << "MaterialModel failed to revertToLastCommit():" ;
00210      theModels[i]->Print(cerr);
00211  }
00212     
00213     return 0;    
00214 }
00215 
00216 
00217 int 
00218 ParallelMaterial::revertToStart(void)
00219 {
00220     Cfailed = 0;
00221 
00222     // invoke commitState() on each of local MaterialModel objects
00223     for (int i=0; i<numMaterials; i++)
00224  if (theModels[i]->revertToStart() != 0) {
00225      cerr << "WARNING ParallelMaterial::revertToStart() ";
00226      cerr << "MaterialModel failed to revertToStart():" ;
00227      theModels[i]->Print(cerr);
00228  }
00229     
00230     return 0;    
00231 }
00232 
00233 
00234 
00235 UniaxialMaterial *
00236 ParallelMaterial::getCopy(void)
00237 {
00238     ParallelMaterial *theCopy = new 
00239        ParallelMaterial(this->getTag(),numMaterials,theModels,epsmin,epsmax);
00240 
00241     theCopy->trialStrain = trialStrain;
00242  theCopy->trialStrainRate = trialStrainRate;
00243     theCopy->Cfailed = Cfailed;
00244     theCopy->Tfailed = Tfailed;
00245 
00246     return theCopy;
00247 }
00248 
00249 
00250 int 
00251 ParallelMaterial::sendSelf(int cTag, Channel &theChannel)
00252 {
00253     Vector data(6);
00254 
00255     // check to see if we have a database tag for the other ID,
00256     // the object requires two database tags as sends two ID's.
00257     if (otherDbTag == 0) 
00258       otherDbTag = theChannel.getDbTag();
00259 
00260     data(0) = this->getTag();
00261     data(1) = numMaterials;
00262     data(2) = otherDbTag;
00263     data(3) = epsmin;
00264     data(4) = epsmax;
00265     data(5) = Cfailed;
00266 
00267     theChannel.sendVector(this->getDbTag(), cTag, data);
00268     
00269     // now create an ID containing the class tags and dbTags of all
00270     // the MaterialModel objects in this ParallelMaterial
00271     // then send each of the MaterialModel objects
00272     ID classTags(numMaterials*2);
00273     for (int i=0; i<numMaterials; i++) {
00274  classTags(i) = theModels[i]->getClassTag();
00275  int matDbTag = theModels[i]->getDbTag();
00276  if (matDbTag == 0) {
00277    matDbTag  = theChannel.getDbTag();
00278    if (matDbTag != 0)
00279      theModels[i]->setDbTag(matDbTag);
00280  }
00281  classTags(i+numMaterials) = matDbTag;
00282     }
00283     theChannel.sendID(otherDbTag, cTag, classTags);
00284     for (int j=0; j<numMaterials; j++)
00285  theModels[j]->sendSelf(cTag, theChannel);
00286     
00287     return 0;
00288 }
00289 
00290 int 
00291 ParallelMaterial::recvSelf(int cTag, Channel &theChannel, 
00292     FEM_ObjectBroker &theBroker)
00293 {
00294     Vector data(6);
00295     theChannel.recvVector(this->getDbTag(), cTag, data);
00296     this->setTag(int(data(0)));
00297     numMaterials = int(data(1));
00298     otherDbTag = int(data(2));
00299     epsmin = data(3);
00300     epsmax = data(4);
00301     Cfailed = int(data(5));
00302 
00303     // create and receive an ID for the classTags and dbTags of the local 
00304     // MaterialModel objects
00305     ID classTags(numMaterials*2);
00306     theChannel.recvID(otherDbTag, cTag, classTags);
00307     theModels = new UniaxialMaterial *[numMaterials];
00308 
00309     // create space for the objects
00310     if (theModels == 0) {
00311  cerr << "FATAL ParallelMaterial::recvSelf() ";
00312  cerr << " ran out of memory for array of size: " << numMaterials << "\n";
00313  exit(-1);
00314     }    
00315 
00316     // now for each of the MaterialModel objects, create a new object
00317     // and invoke recvSelf() on it
00318     for (int i=0; i<numMaterials; i++) {
00319  UniaxialMaterial *theMaterialModel = 
00320      theBroker.getNewUniaxialMaterial(classTags(i));
00321  if (theMaterialModel != 0) {
00322      theModels[i] = theMaterialModel;
00323      theMaterialModel->setDbTag(classTags(i+numMaterials));
00324  }
00325  else {
00326      cerr << "FATAL ParallelMaterial::recvSelf() ";
00327      cerr << " could not get a UniaxialMaterial \n";
00328      exit(-1);
00329  }         
00330  theMaterialModel->recvSelf(cTag, theChannel, theBroker);
00331     }
00332     return 0;
00333 }
00334 
00335 void 
00336 ParallelMaterial::Print(ostream &s, int flag)
00337 {
00338     s << "Parallel tag: " << this->getTag() << endl;
00339     if (epsmin != NEG_INF_STRAIN)
00340       s << "  epsmin: " << epsmin << endl;
00341     if (epsmax != POS_INF_STRAIN)
00342       s << "  epsmax: " << epsmax << endl;
00343     for (int i=0; i<numMaterials; i++) {
00344       s << ' ';
00345       theModels[i]->Print(s, flag);
00346     }
00347     
00348 }
Copyright Contact Us