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 <NodeRecorder.h>
00035 #include <Domain.h>
00036 #include <Node.h>
00037 #include <Vector.h>
00038 #include <ID.h>
00039 #include <Matrix.h>
00040 #include <FE_Datastore.h>
00041 #include <FEM_ObjectBroker.h>
00042
00043 #include <string.h>
00044
00045 NodeRecorder::NodeRecorder()
00046 :Recorder(RECORDER_TAGS_NodeRecorder),
00047 theDofs(0), theNodalTags(0), theNodes(0), response(0),
00048 theDomain(0), theOutputHandler(0),
00049 echoTimeFlag(true), dataFlag(0),
00050 deltaT(0), nextTimeStampToRecord(0.0),
00051 sensitivity(0),
00052 initializationDone(false), numValidNodes(0)
00053 {
00054
00055 }
00056
00057 NodeRecorder::NodeRecorder(const ID &dofs,
00058 const ID &nodes,
00059 int psensitivity,
00060 const char *dataToStore,
00061 Domain &theDom,
00062 OPS_Stream &theOutputHandler,
00063 double dT,
00064 bool timeFlag)
00065 :Recorder(RECORDER_TAGS_NodeRecorder),
00066 theDofs(0), theNodalTags(0), theNodes(0),
00067 response(1 + nodes.Size()*dofs.Size()),
00068 theDomain(&theDom), theOutputHandler(&theOutputHandler),
00069 echoTimeFlag(timeFlag), dataFlag(0),
00070 deltaT(dT), nextTimeStampToRecord(0.0),
00071 sensitivity(psensitivity),
00072 initializationDone(false), numValidNodes(0)
00073 {
00074
00075
00076
00077
00078 int numDOF = dofs.Size();
00079
00080 if (numDOF != 0) {
00081
00082 theDofs = new ID(numDOF);
00083
00084 int count = 0;
00085 int i;
00086 for (i=0; i<numDOF; i++) {
00087 int dof = dofs(i);
00088 if (dof >= 0) {
00089 (*theDofs)[count] = dof;
00090 count++;
00091 } else {
00092 opserr << "NodeRecorder::NodeRecorder - invalid dof " << dof;
00093 opserr << " will be ignored\n";
00094 }
00095 }
00096 }
00097
00098
00099
00100
00101
00102 int numNode = nodes.Size();
00103 if (numNode != 0) {
00104 theNodalTags = new ID(nodes);
00105
00106 if (theNodalTags == 0) {
00107 opserr << "NodeRecorder::NodeRecorder - out of memory\n";
00108 }
00109 }
00110
00111
00112
00113
00114
00115
00116
00117 if (dataToStore == 0 || (strcmp(dataToStore, "disp") == 0)) {
00118 dataFlag = 0;
00119 } else if ((strcmp(dataToStore, "vel") == 0)) {
00120 dataFlag = 1;
00121 } else if ((strcmp(dataToStore, "accel") == 0)) {
00122 dataFlag = 2;
00123 } else if ((strcmp(dataToStore, "incrDisp") == 0)) {
00124 dataFlag = 3;
00125 } else if ((strcmp(dataToStore, "incrDeltaDisp") == 0)) {
00126 dataFlag = 4;
00127 } else if ((strcmp(dataToStore, "unbalance") == 0)) {
00128 dataFlag = 5;
00129 } else if ((strcmp(dataToStore, "unbalanceInclInertia") == 0)) {
00130 dataFlag = 6;
00131 } else if ((strcmp(dataToStore, "reaction") == 0)) {
00132 dataFlag = 7;
00133 } else if (((strcmp(dataToStore, "reactionIncInertia") == 0))
00134 || ((strcmp(dataToStore, "reactionIncludingInertia") == 0))) {
00135 dataFlag = 8;
00136 } else if ((strncmp(dataToStore, "eigen",5) == 0)) {
00137 int mode = atoi(&(dataToStore[5]));
00138 if (mode > 0)
00139 dataFlag = 10 + mode;
00140 else
00141 dataFlag = 6;
00142 } else if ((strncmp(dataToStore, "sensitivity",11) == 0)) {
00143 int grad = atoi(&(dataToStore[11]));
00144 if (grad > 0)
00145 dataFlag = 1000 + grad;
00146 else
00147 dataFlag = 6;
00148 } else if ((strncmp(dataToStore, "velSensitivity",14) == 0)) {
00149 int grad = atoi(&(dataToStore[14]));
00150 if (grad > 0)
00151 dataFlag = 2000 + grad;
00152 else
00153 dataFlag = 6;
00154 } else if ((strncmp(dataToStore, "accSensitivity",14) == 0)) {
00155 int grad = atoi(&(dataToStore[14]));
00156 if (grad > 0)
00157 dataFlag = 3000 + grad;
00158 else
00159 dataFlag = 6;
00160
00161 } else {
00162 dataFlag = 6;
00163 opserr << "NodeRecorder::NodeRecorder - dataToStore " << dataToStore;
00164 opserr << "not recognized (disp, vel, accel, incrDisp, incrDeltaDisp)\n";
00165 }
00166 }
00167
00168
00169 NodeRecorder::~NodeRecorder()
00170 {
00171 theOutputHandler->endTag();
00172 theOutputHandler->endTag();
00173
00174 if (theOutputHandler != 0)
00175 delete theOutputHandler;
00176
00177 if (theDofs != 0)
00178 delete theDofs;
00179
00180 if (theNodalTags != 0)
00181 delete theNodalTags;
00182
00183 if (theNodes != 0)
00184 delete [] theNodes;
00185 }
00186
00187 int
00188 NodeRecorder::record(int commitTag, double timeStamp)
00189 {
00190 if (theDomain == 0 || theNodalTags == 0 || theDofs == 0) {
00191 return 0;
00192 }
00193
00194 if (theOutputHandler == 0) {
00195 opserr << "NodeRecorder::record() - no DataOutputHandler has been set\n";
00196 return -1;
00197 }
00198
00199 if (initializationDone != true)
00200 if (this->initialize() != 0) {
00201 opserr << "NodeRecorder::record() - failed in initialize()\n";
00202 return -1;
00203 }
00204
00205 int numDOF = theDofs->Size();
00206
00207 if (deltaT == 0.0 || timeStamp >= nextTimeStampToRecord) {
00208
00209 if (deltaT != 0.0)
00210 nextTimeStampToRecord = timeStamp + deltaT;
00211
00212
00213
00214
00215
00216
00217
00218 if (dataFlag == 7)
00219 theDomain->calculateNodalReactions(false);
00220 else if (dataFlag == 8)
00221 theDomain->calculateNodalReactions(true);
00222
00223
00224
00225
00226
00227
00228 int timeOffset = 0;
00229 if (echoTimeFlag == true) {
00230 timeOffset = 1;
00231 response(0) = timeStamp;
00232 }
00233
00234
00235
00236
00237
00238
00239 for (int i=0; i<numValidNodes; i++) {
00240 int cnt = i*numDOF + timeOffset;
00241 Node *theNode = theNodes[i];
00242 if (dataFlag == 0) {
00243
00244 if (sensitivity==0) {
00245 const Vector &theResponse = theNode->getTrialDisp();
00246 for (int j=0; j<numDOF; j++) {
00247 int dof = (*theDofs)(j);
00248 if (theResponse.Size() > dof) {
00249 response(cnt) = theResponse(dof);
00250 }
00251 else {
00252 response(cnt) = 0.0;
00253 }
00254 cnt++;
00255 }
00256 }
00257 else {
00258 for (int j=0; j<numDOF; j++) {
00259 int dof = (*theDofs)(j);
00260
00261 response(cnt) = theNode->getDispSensitivity(dof+1, sensitivity);
00262 cnt++;
00263 }
00264 }
00265
00266
00267 } else if (dataFlag == 1) {
00268 const Vector &theResponse = theNode->getTrialVel();
00269 for (int j=0; j<numDOF; j++) {
00270 int dof = (*theDofs)(j);
00271 if (theResponse.Size() > dof) {
00272 response(cnt) = theResponse(dof);
00273 } else
00274 response(cnt) = 0.0;
00275
00276 cnt++;
00277 }
00278 } else if (dataFlag == 2) {
00279 const Vector &theResponse = theNode->getTrialAccel();
00280 for (int j=0; j<numDOF; j++) {
00281 int dof = (*theDofs)(j);
00282 if (theResponse.Size() > dof) {
00283 response(cnt) = theResponse(dof);
00284 } else
00285 response(cnt) = 0.0;
00286
00287 cnt++;
00288 }
00289 } else if (dataFlag == 3) {
00290 const Vector &theResponse = theNode->getIncrDisp();
00291 for (int j=0; j<numDOF; j++) {
00292 int dof = (*theDofs)(j);
00293 if (theResponse.Size() > dof) {
00294 response(cnt) = theResponse(dof);
00295 } else
00296 response(cnt) = 0.0;
00297
00298 cnt++;
00299 }
00300 } else if (dataFlag == 4) {
00301 const Vector &theResponse = theNode->getIncrDeltaDisp();
00302 for (int j=0; j<numDOF; j++) {
00303 int dof = (*theDofs)(j);
00304 if (theResponse.Size() > dof) {
00305 response(cnt) = theResponse(dof);
00306 } else
00307 response(cnt) = 0.0;
00308
00309 cnt++;
00310 }
00311 } else if (dataFlag == 5) {
00312 const Vector &theResponse = theNode->getUnbalancedLoad();
00313 for (int j=0; j<numDOF; j++) {
00314 int dof = (*theDofs)(j);
00315 if (theResponse.Size() > dof) {
00316 response(cnt) = theResponse(dof);
00317 } else
00318 response(cnt) = 0.0;
00319
00320 cnt++;
00321 }
00322
00323 } else if (dataFlag == 6) {
00324 const Vector &theResponse = theNode->getUnbalancedLoadIncInertia();
00325 for (int j=0; j<numDOF; j++) {
00326 int dof = (*theDofs)(j);
00327 if (theResponse.Size() > dof) {
00328 response(cnt) = theResponse(dof);
00329 } else
00330 response(cnt) = 0.0;
00331
00332 cnt++;
00333 }
00334
00335
00336 } else if (dataFlag == 7) {
00337 const Vector &theResponse = theNode->getReaction();
00338 for (int j=0; j<numDOF; j++) {
00339 int dof = (*theDofs)(j);
00340 if (theResponse.Size() > dof) {
00341 response(cnt) = theResponse(dof);
00342 } else
00343 response(cnt) = 0.0;
00344
00345 cnt++;
00346 }
00347
00348
00349 } else if (dataFlag == 8) {
00350 const Vector &theResponse = theNode->getReaction();
00351 for (int j=0; j<numDOF; j++) {
00352 int dof = (*theDofs)(j);
00353 if (theResponse.Size() > dof) {
00354 response(cnt) = theResponse(dof);
00355 } else
00356 response(cnt) = 0.0;
00357
00358 cnt++;
00359 }
00360
00361
00362 } else if (10 <= dataFlag && dataFlag < 1000) {
00363 int mode = dataFlag - 10;
00364 int column = mode - 1;
00365 const Matrix &theEigenvectors = theNode->getEigenvectors();
00366 if (theEigenvectors.noCols() > column) {
00367 int noRows = theEigenvectors.noRows();
00368 for (int j=0; j<numDOF; j++) {
00369 int dof = (*theDofs)(j);
00370 if (noRows > dof) {
00371 response(cnt) = theEigenvectors(dof,column);
00372 } else
00373 response(cnt) = 0.0;
00374 cnt++;
00375 }
00376 }
00377
00378 } else if (dataFlag >= 1000 && dataFlag < 2000) {
00379 int grad = dataFlag - 1000;
00380
00381 for (int j=0; j<numDOF; j++) {
00382 int dof = (*theDofs)(j);
00383 dof += 1;
00384
00385 response(cnt) = theNode->getDispSensitivity(dof, grad);
00386 cnt++;
00387 }
00388
00389 } else if (dataFlag >= 2000 && dataFlag < 3000) {
00390 int grad = dataFlag - 2000;
00391
00392 for (int j=0; j<numDOF; j++) {
00393 int dof = (*theDofs)(j);
00394 dof += 1;
00395
00396 response(cnt) = theNode->getVelSensitivity(dof, grad);
00397 cnt++;
00398 }
00399
00400
00401 } else if (dataFlag >= 3000) {
00402 int grad = dataFlag - 3000;
00403
00404 for (int j=0; j<numDOF; j++) {
00405 int dof = (*theDofs)(j);
00406 dof += 1;
00407
00408 response(cnt) = theNode->getAccSensitivity(dof, grad);
00409 cnt++;
00410 }
00411 }
00412
00413 else {
00414
00415 for (int j=0; j<numDOF; j++) {
00416 response(cnt) = 0.0;
00417 }
00418 }
00419 }
00420
00421
00422 theOutputHandler->write(response);
00423 }
00424
00425 return 0;
00426 }
00427
00428
00429 int
00430 NodeRecorder::setDomain(Domain &theDom)
00431 {
00432 theDomain = &theDom;
00433 return 0;
00434 }
00435
00436
00437 int
00438 NodeRecorder::sendSelf(int commitTag, Channel &theChannel)
00439 {
00440 if (theChannel.isDatastore() == 1) {
00441 opserr << "NodeRecorder::sendSelf() - does not send data to a datastore\n";
00442 return -1;
00443 }
00444
00445 static ID idData(6);
00446 idData.Zero();
00447 if (theDofs != 0)
00448 idData(0) = theDofs->Size();
00449 if (theNodalTags != 0)
00450 idData(1) = theNodalTags->Size();
00451 if (theOutputHandler != 0) {
00452 idData(2) = theOutputHandler->getClassTag();
00453 }
00454
00455 if (echoTimeFlag == true)
00456 idData(3) = 1;
00457 else
00458 idData(3) = 0;
00459
00460 idData(4) = dataFlag;
00461 idData(5) = sensitivity;
00462
00463 if (theChannel.sendID(0, commitTag, idData) < 0) {
00464 opserr << "NodeRecorder::sendSelf() - failed to send idData\n";
00465 return -1;
00466 }
00467
00468 if (theDofs != 0)
00469 if (theChannel.sendID(0, commitTag, *theDofs) < 0) {
00470 opserr << "NodeRecorder::sendSelf() - failed to send dof id's\n";
00471 return -1;
00472 }
00473
00474 if (theNodalTags != 0)
00475 if (theChannel.sendID(0, commitTag, *theNodalTags) < 0) {
00476 opserr << "NodeRecorder::sendSelf() - failed to send nodal tags\n";
00477 return -1;
00478 }
00479
00480 static Vector data(2);
00481 data(0) = deltaT;
00482 data(1) = nextTimeStampToRecord;
00483 if (theChannel.sendVector(0, commitTag, data) < 0) {
00484 opserr << "NodeRecorder::sendSelf() - failed to send data\n";
00485 return -1;
00486 }
00487
00488 if (theOutputHandler->sendSelf(commitTag, theChannel) < 0) {
00489 opserr << "NodeRecorder::sendSelf() - failed to send the DataOutputHandler\n";
00490 return -1;
00491 }
00492
00493 return 0;
00494 }
00495
00496
00497
00498 int
00499 NodeRecorder::recvSelf(int commitTag, Channel &theChannel,
00500 FEM_ObjectBroker &theBroker)
00501 {
00502 if (theChannel.isDatastore() == 1) {
00503 opserr << "NodeRecorder::sendSelf() - does not send data to a datastore\n";
00504 return -1;
00505 }
00506
00507 static ID idData(6);
00508 if (theChannel.recvID(0, commitTag, idData) < 0) {
00509 opserr << "NodeRecorder::recvSelf() - failed to send idData\n";
00510 return -1;
00511 }
00512
00513 int numDOFs = idData(0);
00514 int numNodes = idData(1);
00515
00516 if (idData(3) == 1)
00517 echoTimeFlag = true;
00518 else
00519 echoTimeFlag = false;
00520
00521 dataFlag = idData(4);
00522 sensitivity = idData(5);
00523
00524
00525
00526
00527
00528 if (theDofs == 0 || theDofs->Size() != numDOFs) {
00529 if (theDofs != 0)
00530 delete theDofs;
00531
00532 if (numDOFs != 0) {
00533 theDofs = new ID(numDOFs);
00534 if (theDofs == 0 || theDofs->Size() != numDOFs) {
00535 opserr << "NodeRecorder::recvSelf() - out of memory\n";
00536 return -1;
00537 }
00538 }
00539 }
00540 if (theDofs != 0)
00541 if (theChannel.recvID(0, commitTag, *theDofs) < 0) {
00542 opserr << "NodeRecorder::recvSelf() - failed to recv dof data\n";
00543 return -1;
00544 }
00545
00546
00547
00548
00549
00550 if (theNodalTags == 0 || theNodalTags->Size() != numNodes) {
00551 if (theNodalTags != 0)
00552 delete theNodalTags;
00553
00554 if (numNodes != 0) {
00555 theNodalTags = new ID(numNodes);
00556 if (theNodalTags == 0 || theNodalTags->Size() != numNodes) {
00557 opserr << "NodeRecorder::recvSelf() - out of memory\n";
00558 return -1;
00559 }
00560 }
00561 }
00562 if (theNodalTags != 0)
00563 if (theChannel.recvID(0, commitTag, *theNodalTags) < 0) {
00564 opserr << "NodeRecorder::recvSelf() - failed to recv dof data\n";
00565 return -1;
00566 }
00567
00568
00569 static Vector data(2);
00570 data(0) = deltaT;
00571 data(1) = nextTimeStampToRecord;
00572 if (theChannel.recvVector(0, commitTag, data) < 0) {
00573 opserr << "NodeRecorder::sendSelf() - failed to receive data\n";
00574 return -1;
00575 }
00576
00577 if (theOutputHandler != 0)
00578 delete theOutputHandler;
00579
00580 theOutputHandler = theBroker.getPtrNewStream(idData(2));
00581 if (theOutputHandler == 0) {
00582 opserr << "NodeRecorder::sendSelf() - failed to get a data output handler\n";
00583 return -1;
00584 }
00585
00586 if (theOutputHandler->recvSelf(commitTag, theChannel, theBroker) < 0) {
00587 opserr << "NodeRecorder::sendSelf() - failed to send the DataOutputHandler\n";
00588 return -1;
00589 }
00590
00591 return 0;
00592 }
00593
00594
00595
00596 int
00597 NodeRecorder::initialize(void)
00598 {
00599 if (theDofs == 0 || theNodalTags == 0 || theDomain == 0) {
00600 opserr << "NodeRecorder::initialize() - either nodes, dofs or domain has not been set\n";
00601 return -1;
00602 }
00603
00604 theOutputHandler->tag("OpenSeesOutput");
00605
00606 if (echoTimeFlag == true) {
00607 theOutputHandler->tag("TimeOutput");
00608 theOutputHandler->tag("ResponseType", "time");
00609 theOutputHandler->endTag();
00610 }
00611
00612
00613
00614
00615
00616 if (theNodes != 0)
00617 delete [] theNodes;
00618
00619 numValidNodes = 0;
00620 int i;
00621 int numNode = theNodalTags->Size();
00622 for (i=0; i<numNode; i++) {
00623 int nodeTag = (*theNodalTags)(i);
00624 Node *theNode = theDomain->getNode(nodeTag);
00625 if (theNode != 0) {
00626 numValidNodes++;
00627 }
00628 }
00629
00630 theNodes = new Node *[numValidNodes];
00631 if (theNodes == 0) {
00632 opserr << "NodeRecorder::domainChanged - out of memory\n";
00633 return -1;
00634 }
00635
00636 int count = 0;
00637 for (i=0; i<numNode; i++) {
00638 int nodeTag = (*theNodalTags)(i);
00639 Node *theNode = theDomain->getNode(nodeTag);
00640 if (theNode != 0) {
00641 theNodes[count] = theNode;
00642 count++;
00643 }
00644 }
00645
00646
00647
00648
00649
00650 int timeOffset = 0;
00651 if (echoTimeFlag == true)
00652 timeOffset = 1;
00653
00654 int numValidResponse = numValidNodes*theDofs->Size() + timeOffset;
00655 response.resize(numValidResponse);
00656 response.Zero();
00657
00658
00659
00660
00661
00662 char outputData[32];
00663 char dataType[10];
00664
00665 if (dataFlag == 0) {
00666 strcpy(dataType,"D");
00667 } else if (dataFlag == 1) {
00668 strcpy(dataType,"V");
00669 } else if (dataFlag == 2) {
00670 strcpy(dataType,"A");
00671 } else if (dataFlag == 3) {
00672 strcpy(dataType,"dD");
00673 } else if (dataFlag == 4) {
00674 strcpy(dataType,"ddD");
00675 } else if (dataFlag == 5) {
00676 strcpy(dataType,"U");
00677 } else if (dataFlag == 6) {
00678 strcpy(dataType,"U");
00679 } else if (dataFlag == 7) {
00680 strcpy(dataType,"R");
00681 } else if (dataFlag == 8) {
00682 strcpy(dataType,"R");
00683 } else if (dataFlag > 10) {
00684 sprintf(dataType,"E%d", dataFlag-10);
00685 } else
00686 strcpy(dataType,"Unknown");
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710 char nodeCrdData[20];
00711 sprintf(nodeCrdData,"coord");
00712
00713 for (i=0; i<numValidNodes; i++) {
00714 int nodeTag = theNodes[i]->getTag();
00715 const Vector &nodeCrd = theNodes[i]->getCrds();
00716 int numCoord = nodeCrd.Size();
00717
00718 theOutputHandler->tag("NodeOutput");
00719 theOutputHandler->attr("nodeTag", nodeTag);
00720
00721 for (int j=0; j<3; j++) {
00722 sprintf(nodeCrdData,"coord%d",j+1);
00723 if (j < numCoord)
00724 theOutputHandler->attr(nodeCrdData, nodeCrd(j));
00725 else
00726 theOutputHandler->attr(nodeCrdData, 0.0);
00727 }
00728
00729 for (int k=0; k<theDofs->Size(); k++) {
00730 sprintf(outputData, "%s%d", dataType, k+1);
00731 theOutputHandler->tag("ResponseType",outputData);
00732 }
00733
00734 theOutputHandler->endTag();
00735 }
00736
00737 theOutputHandler->tag("Data");
00738 initializationDone = true;
00739
00740 return 0;
00741 }