Information.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/02/14 23:01:03 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/element/Information.cpp,v $
00024                                                                         
00025                                                                         
00026 // File: ~/element/Information.C
00027 //
00028 // Written: fmk 10/99
00029 // Revised:
00030 //
00031 // Purpose: This file contains the class implementation for Information.
00032 
00033 #include <Information.h>
00034 #include <ID.h>
00035 #include <Vector.h>
00036 #include <Matrix.h>
00037 #include <Tensor.h>
00038 
00039 Information::Information() 
00040   :theType(UnknownType),
00041   theID(0), theVector(0), theMatrix(0), theTensor(0)
00042 {
00043     // does nothing
00044 }
00045 
00046 Information::Information(int val) 
00047   :theType(IntType), theInt(val),
00048   theID(0), theVector(0), theMatrix(0), theTensor(0)
00049 {
00050     // does nothing
00051 }
00052 
00053 Information::Information(double val) 
00054   :theType(DoubleType), theDouble(val),
00055   theID(0), theVector(0), theMatrix(0), theTensor(0)
00056 {
00057   // does nothing
00058 }
00059 
00060 Information::Information(const ID &val) 
00061   :theType(IdType),
00062   theID(0), theVector(0), theMatrix(0), theTensor(0)
00063 {
00064   // Make a copy
00065   theID = new ID(val);
00066 
00067   if (theID == 0)
00068     opserr << "Information::Information -- failed to allocate\n";
00069 }
00070 
00071 Information::Information(const Vector &val) 
00072   :theType(VectorType),
00073   theID(0), theVector(0), theMatrix(0), theTensor(0)
00074 {
00075   // Make a copy
00076   theVector = new Vector(val);
00077   
00078   if (theVector == 0)
00079     opserr << "Information::Information -- failed to allocate Vector\n";
00080 }
00081 
00082 Information::Information(const Matrix &val) 
00083   :theType(MatrixType),
00084    theID(0), theVector(0), theMatrix(0), theTensor(0)
00085 {
00086   // Make a copy
00087   theMatrix = new Matrix(val);
00088   
00089   if (theMatrix == 0)
00090     opserr << "Information::Information -- failed to allocate Matrix\n";
00091 }
00092 
00093 Information::Information(const Tensor &val) 
00094   :theType(TensorType),
00095   theID(0), theVector(0), theMatrix(0), theTensor(0)
00096 {
00097   // Make a copy
00098   theTensor = new Tensor(val);
00099   
00100   if (theTensor == 0)
00101     opserr << "Information::Iformation -- failed to allocate Tensor\n";
00102 }
00103 
00104 Information::~Information() 
00105 {
00106   if (theID != 0)
00107     delete theID;
00108   
00109   if (theVector != 0)
00110     delete theVector;
00111   
00112   if (theMatrix != 0)
00113     delete theMatrix;
00114   
00115   if (theTensor != 0)
00116     delete theTensor;
00117 }
00118 
00119 int 
00120 Information::setInt(int newInt)
00121 {
00122   theInt = newInt;
00123   
00124   return 0;
00125 }
00126 
00127 int 
00128 Information::setDouble(double newDouble)
00129 {
00130   theDouble = newDouble;
00131   
00132   return 0;
00133 }
00134 
00135 int 
00136 Information::setID(const ID &newID)
00137 {
00138   if (theID != 0) {
00139     *theID = newID;
00140     return 0;
00141   } else
00142     return -1;
00143 }
00144 
00145 int 
00146 Information::setVector(const Vector &newVector)
00147 {
00148   if (theVector != 0) {
00149     *theVector = newVector;
00150     return 0;
00151   }
00152   else
00153     return -1;
00154 }
00155 
00156 int 
00157 Information::setMatrix(const Matrix &newMatrix)
00158 {
00159   if (theMatrix != 0) {
00160     *theMatrix = newMatrix;
00161     return 0;
00162   }
00163   else
00164     return -1;
00165 }
00166 
00167 int 
00168 Information::setTensor(const Tensor &newTensor)
00169 {
00170   if (theTensor != 0) {
00171     *theTensor = newTensor;
00172     return 0;
00173   }
00174   else
00175     return -1;
00176 }
00177 
00178 void 
00179 Information::Print(OPS_Stream &s, int flag)
00180 {
00181   if (theType == IntType)
00182     s << theInt << " ";
00183   else if (theType == DoubleType)
00184     s << theDouble << " ";
00185   else if (theType == IdType && theID != 0)
00186     for (int i=0; i<theID->Size(); i++)
00187       s << (*theID)(i) << " ";
00188   else if (theType == VectorType && theVector != 0)
00189     for (int i=0; i<theVector->Size(); i++)
00190       s << (*theVector)(i) << " ";
00191   else if (theType == MatrixType && theMatrix != 0) {
00192     for (int i=0; i<theMatrix->noRows(); i++) {
00193       for (int j=0; j<theMatrix->noCols(); j++)
00194         s <<  (*theMatrix)(i,j) << " ";
00195         s << endln;
00196     }
00197   } else if (theType == TensorType && theTensor != 0)
00198     // No overloaded << for Tensors yet!
00199     //s << *theTensor;
00200     s << "No Tensor output";
00201   else
00202     return;
00203 }
00204 
00205 
00206 void 
00207 Information::Print(ofstream &s, int flag)
00208 {
00209   if (theType == IntType)
00210     s << theInt << " ";
00211   else if (theType == DoubleType)
00212     s << theDouble << " ";
00213   else if (theType == IdType && theID != 0)
00214     for (int i=0; i<theID->Size(); i++)
00215       s << (*theID)(i) << " ";
00216   else if (theType == VectorType && theVector != 0)
00217     for (int i=0; i<theVector->Size(); i++)
00218       s << (*theVector)(i) << " ";
00219   else if (theType == MatrixType && theMatrix != 0) {
00220     for (int i=0; i<theMatrix->noRows(); i++) {
00221       for (int j=0; j<theMatrix->noCols(); j++)
00222         s <<  (*theMatrix)(i,j) << " ";
00223         s << endln;
00224     }
00225   }
00226   else if (theType == TensorType && theTensor != 0)
00227     // No overloaded << for Tensors yet!
00228     //s << *theTensor;
00229     s << "No Tensor output";
00230   else
00231     return;
00232 }
00233 
00234 const Vector &
00235 Information::getData(void) 
00236 {
00237   if (theType == IntType) {
00238     if (theVector == 0) 
00239       theVector = new Vector(1);
00240     (*theVector)(0) = theInt;
00241   } else if (theType == DoubleType) {
00242     if (theVector == 0) 
00243       theVector = new Vector(1);
00244     (*theVector)(0) = theDouble;
00245   } else if (theType == IdType && theID != 0) {
00246     if (theVector == 0) 
00247       theVector = new Vector(theID->Size());
00248     for (int i=0; i<theID->Size(); i++)
00249       (*theVector)(i) =  (*theID)(i);
00250   } else if (theType == MatrixType && theMatrix != 0) {
00251     int noRows = theMatrix->noRows();
00252     int noCols = theMatrix->noCols();
00253     if (theVector == 0) 
00254       theVector = new Vector(noRows * noCols);
00255     for (int i=0; i<noRows; i++)
00256       for (int j=0; j<noCols; j++)
00257         (*theVector)(i) = (*theMatrix)(i,j);
00258   }
00259   
00260   return *theVector;
00261 }

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