TriangleSeries.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 $
00022 // $Date: 2005/12/15 00:35:47 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/domain/pattern/TriangleSeries.cpp,v $
00024 
00025 // Written: Andreas Schellenberg (andreas.schellenberg@gmx.net)
00026 // Created: 02/04
00027 // Revision: A
00028 //
00029 // Purpose: This file contains the class implementation of TriangleSeries.
00030 //
00031 // What: "@(#) TriangleSeries.cpp, revA"
00032 
00033 
00034 #include <TriangleSeries.h>
00035 #include <Vector.h>
00036 #include <Channel.h>
00037 #include <classTags.h>
00038 
00039 #include <math.h>
00040 
00041 
00042 TriangleSeries::TriangleSeries(double startTime, double finishTime,
00043     double T, double phi, double theFactor)
00044     : TimeSeries(TSERIES_TAG_TriangleSeries),
00045     tStart(startTime),tFinish(finishTime),
00046     period(T),shift(phi),cFactor(theFactor)
00047 {
00048         if (period == 0.0)  {
00049                 opserr << "TriangleSeries::TriangleSeries -- input period is zero, setting period to 1\n";
00050                 period = 1;
00051         }
00052 }
00053 
00054 
00055 TriangleSeries::TriangleSeries()
00056     : TimeSeries(TSERIES_TAG_TriangleSeries),
00057     tStart(0.0),tFinish(0.0),
00058     period(1.0),shift(0.0),cFactor(1.0)
00059 {
00060         // does nothing
00061 }
00062 
00063 
00064 TriangleSeries::~TriangleSeries()
00065 {
00066         // does nothing
00067 }
00068 
00069 
00070 double TriangleSeries::getFactor(double pseudoTime)
00071 {       
00072         if (tStart <= pseudoTime && pseudoTime <= tFinish)  {
00073                 double slope = cFactor/(period/4);
00074                 double k = (pseudoTime+shift)/period - floor((pseudoTime+shift)/period);
00075                 if (k < 0.25)
00076                         return slope*k*period;
00077                 else if (k < 0.75)
00078                         return cFactor-slope*(k-0.25)*period;
00079                 else if (k < 1.00)
00080                         return -cFactor + slope*(k-0.75)*period;
00081                 else
00082                         return 0;
00083         }
00084         else
00085                 return 0;
00086 }
00087 
00088 
00089 int TriangleSeries::sendSelf(int commitTag, Channel &theChannel)
00090 {
00091         int dbTag = this->getDbTag();
00092         Vector data(5);
00093         data(0) = cFactor;
00094         data(1) = tStart;       
00095         data(2) = tFinish;
00096         data(3) = period;
00097         data(4) = shift;
00098         int result = theChannel.sendVector(dbTag,commitTag, data);
00099         if (result < 0)  {
00100                 opserr << "TriangleSeries::sendSelf() - channel failed to send data\n";
00101                 return result;
00102         }
00103         return 0;
00104 }
00105 
00106 
00107 int TriangleSeries::recvSelf(int commitTag, Channel &theChannel, 
00108     FEM_ObjectBroker &theBroker)
00109 {
00110         int dbTag = this->getDbTag();
00111         Vector data(5);
00112         int result = theChannel.recvVector(dbTag,commitTag, data);
00113         if (result < 0)  {
00114                 opserr << "TriangleSeries::sendSelf() - channel failed to receive data\n";
00115                 cFactor = 1.0;
00116                 tStart  = 0.0;
00117                 tFinish = 0.0;
00118                 period  = 1.0;
00119                 shift   = 0.0;
00120                 return result;
00121         }
00122         cFactor = data(0);
00123         tStart  = data(1);
00124         tFinish = data(2);
00125         period  = data(3);
00126         shift   = data(4);
00127         
00128         return 0;    
00129 }
00130 
00131 
00132 void TriangleSeries::Print(OPS_Stream &s, int flag)
00133 {
00134         s << "Triangle Series" << endln;
00135         s << "\tFactor: " << cFactor << endln;
00136         s << "\ttStart: " << tStart << endln;
00137         s << "\ttFinish: " << tFinish << endln;
00138         s << "\tPeriod: " << period << endln;
00139         s << "\tPhase Shift: " << shift << endln;
00140 }

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