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 #include <MultiSupportPattern.h>
00032 #include <GroundMotion.h>
00033
00034 #include <FEM_ObjectBroker.h>
00035 #include <Domain.h>
00036 #include <SP_Constraint.h>
00037 #include <SP_ConstraintIter.h>
00038 #include <stdlib.h>
00039 #include <Channel.h>
00040 #include <ErrorHandler.h>
00041
00042 MultiSupportPattern::MultiSupportPattern(int tag, int _classTag)
00043 :LoadPattern(tag, _classTag),
00044 theMotions(0), theMotionTags(0,16), numMotions(0), dbMotions(0)
00045 {
00046
00047 }
00048
00049
00050 MultiSupportPattern::MultiSupportPattern(int tag)
00051 :LoadPattern(tag, PATTERN_TAG_MultiSupportPattern),
00052 theMotions(0), theMotionTags(0,16), numMotions(0), dbMotions(0)
00053 {
00054
00055 }
00056
00057
00058 MultiSupportPattern::MultiSupportPattern()
00059 :LoadPattern(0, PATTERN_TAG_MultiSupportPattern),
00060 theMotions(0), theMotionTags(0,16), numMotions(0), dbMotions(0)
00061 {
00062
00063 }
00064
00065 MultiSupportPattern::~MultiSupportPattern()
00066 {
00067
00068 for (int i=0; i<numMotions; i++)
00069 delete theMotions[i];
00070
00071 if (theMotions != 0)
00072
00073 delete [] theMotions;
00074 }
00075
00076
00077
00078 void
00079 MultiSupportPattern::applyLoad(double time)
00080 {
00081 SP_Constraint *sp;
00082 SP_ConstraintIter &theIter = this->getSPs();
00083 while ((sp = theIter()) != 0)
00084 sp->applyConstraint(time);
00085 }
00086
00087
00088 int
00089 MultiSupportPattern::addMotion(GroundMotion &theMotion, int tag)
00090 {
00091
00092 if (theMotionTags.getLocation(tag) >= 0) {
00093 opserr << "MultiSupportPattern::addMotion - could not add new, motion wih same tag exists\n";
00094 return -1;
00095 }
00096
00097
00098 GroundMotion **newMotions = new GroundMotion *[numMotions+1];
00099
00100 if (newMotions == 0) {
00101 opserr << "MultiSupportPattern::addMotion - could not add new, out of mem\n";
00102 return -1;
00103 }
00104
00105
00106 for (int i=0; i<numMotions; i++)
00107 newMotions[i] = theMotions[i];
00108
00109
00110 newMotions[numMotions] = &theMotion;
00111
00112
00113 if (theMotions != 0)
00114 delete [] theMotions;
00115
00116
00117 theMotions = newMotions;
00118 theMotionTags[numMotions] = tag;
00119 numMotions++;
00120
00121 return 0;
00122 }
00123
00124
00125
00126 GroundMotion *
00127 MultiSupportPattern::getMotion(int tag)
00128 {
00129 int loc = theMotionTags.getLocation(tag);
00130 if (loc < 0)
00131 return 0;
00132 else
00133 return theMotions[loc];
00134
00135 }
00136
00137
00138 bool
00139 MultiSupportPattern::addNodalLoad(NodalLoad *)
00140 {
00141 opserr << "MultiSupportPattern::addNodalLoad() - cannot add NodalLoad to EQ pattern\n";
00142 return false;
00143 }
00144
00145 bool
00146 MultiSupportPattern::addElementalLoad(ElementalLoad *)
00147 {
00148 opserr << "MultiSupportPattern::addElementalLoad() - cannot add ElementalLoad to EQ pattern\n";
00149 return false;
00150 }
00151
00152
00153
00154 int
00155 MultiSupportPattern::sendSelf(int commitTag, Channel &theChannel)
00156 {
00157
00158
00159
00160
00161 int myDbTag = this->getDbTag();
00162
00163 if (this->LoadPattern::sendSelf(commitTag, theChannel) < 0) {
00164 opserr << "MultiSupportPattern::sendSelf() - LoadPattern class failed in sendSelf()";
00165 return -1;
00166 }
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176 static ID myData(3);
00177 myData(0) = numMotions;
00178 if (dbMotions == 0)
00179 dbMotions = theChannel.getDbTag();
00180 myData(1) = dbMotions;
00181
00182 if (theChannel.sendID(myDbTag, commitTag, myData) < 0) {
00183 opserr << "MultiSupportPattern::sendSelf - channel failed to send the initial ID\n";
00184 return -1;
00185 }
00186
00187
00188 if (numMotions != 0) {
00189 ID motionData(numMotions*2);
00190 GroundMotion *theMotion;
00191 for (int i=0; i<numMotions; i++) {
00192 theMotion = theMotions[i];
00193 motionData(i*2) = theMotion->getClassTag();
00194 int dbTag = theMotion->getDbTag();
00195
00196
00197
00198 if (dbTag == 0 && myDbTag != 0) {
00199 dbTag = theChannel.getDbTag();
00200 if (dbTag != 0)
00201 theMotion->setDbTag(dbTag);
00202 }
00203 motionData(i*2+1) = dbTag;
00204 }
00205
00206
00207 if (theChannel.sendID(dbMotions, commitTag, motionData) < 0) {
00208 opserr << "MultiSupportPattern::sendSelf - channel failed to send the NodalLoads ID\n";
00209 return -4;
00210 }
00211
00212
00213 for (int j=0; j<numMotions; j++) {
00214 theMotion = theMotions[j];
00215 if (theMotion->sendSelf(commitTag, theChannel) < 0) {
00216 opserr << "MultiSupportPattern::sendSelf - ground motion failed in sendSelf\n";
00217 return -7;
00218 }
00219 }
00220 }
00221
00222
00223 return 0;
00224 }
00225
00226 int
00227 MultiSupportPattern::recvSelf(int commitTag, Channel &theChannel,
00228 FEM_ObjectBroker &theBroker)
00229 {
00230
00231
00232 int myDbTag = this->getDbTag();
00233
00234 if (this->LoadPattern::recvSelf(commitTag, theChannel, theBroker) < 0) {
00235 opserr << "MultiSupportPattern::recvSelf() - LoadPattern class failed in sendSelf()";
00236 return -1;
00237 }
00238
00239
00240 if (theMotions != 0) {
00241 for (int i=0; i<numMotions; i++)
00242 if (theMotions[i] != 0)
00243 delete theMotions[i];
00244 delete [] theMotions;
00245 numMotions = 0;
00246 }
00247
00248
00249
00250
00251
00252 static ID myData(3);
00253 if (theChannel.recvID(myDbTag, commitTag, myData) < 0) {
00254 opserr << "MultiSupportPattern::sendSelf - channel failed to send the initial ID\n";
00255 return -1;
00256 }
00257
00258 int numMotions = myData(0);
00259 int dbMotions = myData(1);
00260
00261 if (numMotions != 0) {
00262 ID motionData(numMotions*2);
00263
00264
00265 if (theChannel.recvID(dbMotions, commitTag, motionData) < 0) {
00266 opserr << "MultiSupportPattern::sendSelf - channel failed to send the NodalLoads ID\n";
00267 return -4;
00268 }
00269
00270 theMotions = new GroundMotion *[numMotions];
00271 if (theMotions == 0) {
00272 opserr << "MultiSupportPattern::recvSelf() - out of memory\n";
00273 return -1;
00274 }
00275
00276 GroundMotion *theMotion;
00277 for (int i=0; i<numMotions; i++) {
00278 theMotion = theBroker.getNewGroundMotion(motionData(i*2));
00279 if (theMotion == 0) {
00280 return -1;
00281 }
00282
00283 theMotion->setDbTag(motionData(i*2+1));
00284
00285 if (theMotion->recvSelf(commitTag, theChannel, theBroker) < 0) {
00286 opserr << "MultiSupportPattern::sendSelf - ground motion failed in sendSelf\n";
00287 return -7;
00288 }
00289 }
00290 }
00291 return 0;
00292 }
00293
00294 void
00295 MultiSupportPattern::Print(OPS_Stream &s, int flag)
00296 {
00297 s << "MultiSupportPattern tag: " << this->getTag() << endln;
00298 SP_Constraint *sp;
00299 SP_ConstraintIter &theIter = this->getSPs();
00300 while ((sp = theIter()) != 0)
00301 sp->Print(s, flag);
00302 }
00303
00304 LoadPattern *
00305 MultiSupportPattern::getCopy(void)
00306 {
00307 LoadPattern *theCopy = new MultiSupportPattern(this->getTag());
00308 return theCopy;
00309 }