00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <PulseSeries.h>
00035 #include <Vector.h>
00036 #include <Channel.h>
00037 #include <classTags.h>
00038
00039 #include <math.h>
00040
00041
00042 PulseSeries::PulseSeries(double startTime, double finishTime,
00043 double T, double pulseWidth, double phi, double theFactor)
00044 : TimeSeries(TSERIES_TAG_PulseSeries),
00045 tStart(startTime),tFinish(finishTime),
00046 period(T),pWidth(pulseWidth),shift(phi),cFactor(theFactor)
00047 {
00048 if (period == 0.0) {
00049 opserr << "PulseSeries::PulseSeries -- input period is zero, setting period to 1\n";
00050 period = 1;
00051 }
00052 }
00053
00054
00055 PulseSeries::PulseSeries()
00056 : TimeSeries(TSERIES_TAG_PulseSeries),
00057 tStart(0.0),tFinish(0.0),
00058 period(1.0),pWidth(0.5),shift(0.0),cFactor(1.0)
00059 {
00060
00061 }
00062
00063
00064 PulseSeries::~PulseSeries()
00065 {
00066
00067 }
00068
00069
00070 double PulseSeries::getFactor(double pseudoTime)
00071 {
00072 if (tStart <= pseudoTime && pseudoTime <= tFinish) {
00073 double k = (pseudoTime+shift)/period - floor((pseudoTime+shift)/period);
00074 if (k < pWidth)
00075 return cFactor;
00076 else if (k < 1.00)
00077 return 0;
00078 else
00079 return 0;
00080 }
00081 else
00082 return 0;
00083 }
00084
00085
00086 int PulseSeries::sendSelf(int commitTag, Channel &theChannel)
00087 {
00088 int dbTag = this->getDbTag();
00089 Vector data(6);
00090 data(0) = cFactor;
00091 data(1) = tStart;
00092 data(2) = tFinish;
00093 data(3) = period;
00094 data(4) = pWidth;
00095 data(5) = shift;
00096 int result = theChannel.sendVector(dbTag,commitTag, data);
00097 if (result < 0) {
00098 opserr << "PulseSeries::sendSelf() - channel failed to send data\n";
00099 return result;
00100 }
00101 return 0;
00102 }
00103
00104
00105 int PulseSeries::recvSelf(int commitTag, Channel &theChannel,
00106 FEM_ObjectBroker &theBroker)
00107 {
00108 int dbTag = this->getDbTag();
00109 Vector data(6);
00110 int result = theChannel.recvVector(dbTag,commitTag, data);
00111 if (result < 0) {
00112 opserr << "PulseSeries::sendSelf() - channel failed to receive data\n";
00113 cFactor = 1.0;
00114 tStart = 0.0;
00115 tFinish = 0.0;
00116 period = 1.0;
00117 pWidth = 0.5;
00118 shift = 0.0;
00119 return result;
00120 }
00121 cFactor = data(0);
00122 tStart = data(1);
00123 tFinish = data(2);
00124 period = data(3);
00125 pWidth = data(4);
00126 shift = data(5);
00127
00128 return 0;
00129 }
00130
00131
00132 void PulseSeries::Print(OPS_Stream &s, int flag)
00133 {
00134 s << "Pulse Series" << endln;
00135 s << "\tFactor: " << cFactor << endln;
00136 s << "\ttStart: " << tStart << endln;
00137 s << "\ttFinish: " << tFinish << endln;
00138 s << "\tPeriod: " << period << endln;
00139 s << "\tPulse Width: " << pWidth << endln;
00140 s << "\tPhase Shift: " << shift << endln;
00141 }