int XC::ElementRecorder::record(int commitTag, double timeStamp) { // // check that initialization has been done // if(initializationDone == false) { if(this->initialize() != 0) { std::cerr << "XC::ElementRecorder::record() - failed to initialize\n"; return -1; } } assert(theHandler); int result = 0; if(deltaT == 0.0 || timeStamp >= nextTimeStampToRecord) { if(deltaT != 0.0) nextTimeStampToRecord = timeStamp + deltaT; int loc = 0; if(echoTimeFlag == true) data(loc++) = timeStamp; // // for each element if responses exist, put them in response vector // const size_t numEle= eleID.Size(); assert(theResponses.size()>=numEle); for(size_t i=0; i< numEle; i++) { if(theResponses[i]) { // ask the element for the reponse int res; if(( res = theResponses[i]->getResponse()) < 0) result += res; else { Information &eleInfo = theResponses[i]->getInformation(); const Vector &eleData = eleInfo.getData(); for(int j=0; j<eleData.Size(); j++) data(loc++) = eleData(j); } } } // // send the response vector to the output handler for o/p // theHandler->write(data); } // succesfull completion - return 0 return result; }
int EnvelopeElementRecorder::record(int commitTag, double timeStamp) { // // check that initialization has been done // if (initializationDone == false) { if (this->initialize() != 0) { opserr << "ElementRecorder::record() - failed to initialize\n"; return -1; } } int result = 0; if (deltaT == 0.0 || timeStamp >= nextTimeStampToRecord) { if (deltaT != 0.0) nextTimeStampToRecord = timeStamp + deltaT; int loc = 0; // for each element do a getResponse() & put the result in current data for (int i=0; i< numEle; i++) { if (theResponses[i] != 0) { // ask the element for the reponse int res; if (( res = theResponses[i]->getResponse()) < 0) result += res; else { // from the response determine no of cols for each Information &eleInfo = theResponses[i]->getInformation(); const Vector &eleData = eleInfo.getData(); // for (int j=0; j<eleData.Size(); j++) // (*currentData)(loc++) = eleData(j); if (numDOF == 0) { for (int j=0; j<eleData.Size(); j++) (*currentData)(loc++) = eleData(j); } else { int dataSize = eleData.Size(); for (int j=0; j<numDOF; j++) { int index = (*dof)(j); if (index >= 0 && index < dataSize) (*currentData)(loc++) = eleData(index); else (*currentData)(loc++) = 0.0; } } } } } int sizeData = currentData->Size(); if (echoTimeFlag == false) { bool writeIt = false; if (first == true) { for (int i=0; i<sizeData; i++) { (*data)(0,i) = (*currentData)(i); (*data)(1,i) = (*currentData)(i); (*data)(2,i) = fabs((*currentData)(i)); first = false; writeIt = true; } } else { for (int i=0; i<sizeData; i++) { double value = (*currentData)(i); if ((*data)(0,i) > value) { (*data)(0,i) = value; double absValue = fabs(value); if ((*data)(2,i) < absValue) (*data)(2,i) = absValue; writeIt = true; } else if ((*data)(1,i) < value) { (*data)(1,i) = value; double absValue = fabs(value); if ((*data)(2,i) < absValue) (*data)(2,i) = absValue; writeIt = true; } } } } else { sizeData /= 2; bool writeIt = false; if (first == true) { for (int i=0; i<sizeData; i++) { (*data)(0,i*2) = timeStamp; (*data)(1,i*2) = timeStamp; (*data)(2,i*2) = timeStamp; (*data)(0,i*2+1) = (*currentData)(i); (*data)(1,i*2+1) = (*currentData)(i); (*data)(2,i*2+1) = fabs((*currentData)(i)); first = false; writeIt = true; } } else { for (int i=0; i<sizeData; i++) { double value = (*currentData)(i); if ((*data)(0,2*i+1) > value) { (*data)(0,i*2) = timeStamp; (*data)(0,i*2+1) = value; double absValue = fabs(value); if ((*data)(2,i*2+1) < absValue) { (*data)(2,i*2+1) = absValue; (*data)(2,i*2) = timeStamp; } writeIt = true; } else if ((*data)(1,i*2+1) < value) { (*data)(1,i*2) = timeStamp; (*data)(1,i*2+1) = value; double absValue = fabs(value); if ((*data)(2,i*2+1) < absValue) { (*data)(2,i*2) = timeStamp; (*data)(2,i*2+1) = absValue; } writeIt = true; } } } } } // succesfull completion - return 0 return result; }
int NormElementRecorder::record(int commitTag, double timeStamp) { // // check that initialization has been done // if (initializationDone == false) { if (this->initialize() != 0) { opserr << "NormElementRecorder::record() - failed to initialize\n"; return -1; } } int result = 0; if (deltaT == 0.0 || timeStamp >= nextTimeStampToRecord) { if (deltaT != 0.0) nextTimeStampToRecord = timeStamp + deltaT; int loc = 0; if (echoTimeFlag == true) (*data)(loc++) = timeStamp; // // for each element if responses exist, put them in response vector // for (int i=0; i< numEle; i++) { if (theResponses[i] != 0) { // ask the element for the reponse int res; if (( res = theResponses[i]->getResponse()) < 0) result += res; else { Information &eleInfo = theResponses[i]->getInformation(); const Vector &eleData = eleInfo.getData(); double normV = 0.0; if (numDOF == 0) { for (int j=0; j<eleData.Size(); j++) normV += eleData(j)*eleData(j); } else { int dataSize = data->Size(); for (int j=0; j<numDOF; j++) { int index = (*dof)(j); if (index >= 0 && index < dataSize) normV += eleData(index) * eleData(index); } } (*data)(loc++) = sqrt(normV); } } } // // send the response vector to the output handler for o/p // theOutputHandler->write(*data); } // succesfull completion - return 0 return result; }
int LoadPattern::recvSelf(int cTag, Channel &theChannel, FEM_ObjectBroker &theBroker) { // get my current database tag // NOTE - dbTag equals 0 if not sending to a database OR has not yet been sent int myDbTag = this->getDbTag(); // into an ID we place all info needed to determine state of LoadPattern int numNod, numEle, numSPs; ID lpData(11); if (theChannel.recvID(myDbTag, cTag, lpData) < 0) { opserr << "LoadPattern::recvSelf - channel failed to recv the initial ID\n"; return -1; } isConstant = lpData(7); this->setTag(lpData(10)); if (isConstant == 0) { // we must recv the load factor in a Vector Vector data(2); if (theChannel.recvVector(myDbTag, cTag, data) < 0) { opserr << "LoadPattern::recvSelf - channel failed to recv the Vector\n"; return -2; } loadFactor = data(0); scaleFactor = data(1); } // read data about the time series if (lpData(8) != -1) { if (theSeries == 0) { theSeries = theBroker.getNewTimeSeries(lpData(8)); } else if (theSeries->getClassTag() != lpData(8)) { delete theSeries; theSeries = theBroker.getNewTimeSeries(lpData(8)); } if (theSeries == 0) { opserr << "LoadPattern::recvSelf - failed to create TimeSeries\n"; return -3; } theSeries->setDbTag(lpData(9)); if (theSeries->recvSelf(cTag, theChannel, theBroker) < 0) { opserr << "LoadPattern::recvSelf - the TimeSeries failed to recv\n"; return -3; } } /* if (theChannel.isDatastore() == 1) { static ID theLastSendTag(1); if (theChannel.recvID(myDbTag,0,theLastSendTag) == 0) lastGeoSendTag = theLastSendTag(0); } */ if (lastChannel != theChannel.getTag() || currentGeoTag != lpData(0) || theChannel.isDatastore() == 0) { // clear out the all the components in the current load pattern this->clearAll(); lastChannel = theChannel.getTag(); currentGeoTag = lpData(0); numNod = lpData(1); numEle = lpData(2); numSPs = lpData(3); dbNod = lpData(4); dbEle = lpData(5); dbSPs = lpData(6); // // now we rebuild the nodal loads // // first get the information from the domainData about the nodes if (numNod != 0) { ID nodeData(2*numNod); // now receive the ID about the nodes, class tag and dbTags if (theChannel.recvID(dbNod, currentGeoTag, nodeData) < 0) { opserr << "LoadPAttern::recvSelf - channel failed to recv the NodalLoad ID\n"; return -2; } // now for each NodalLoad we 1) get a new node of the correct type from the ObjectBroker // 2) ensure the node exists and set it's dbTag, 3) we invoke recvSelf on this new // blank node and 4) add this node to the domain int loc = 0; for (int i=0; i<numNod; i++) { int classTag = nodeData(loc); int dbTag = nodeData(loc+1); NodalLoad *theNode = theBroker.getNewNodalLoad(classTag); if (theNode == 0) { opserr << "LoadPattern::recv - cannot create NodalLoad with classTag " << classTag << endln; return -2; } theNode->setDbTag(dbTag); if (theNode->recvSelf(cTag, theChannel, theBroker) < 0) { opserr << "LoadPattern::recvSelf - NodalLoad with dbTag " << dbTag << " failed in recvSelf\n"; return -2; } if (this->addNodalLoad(theNode) == false) { opserr << "LoadPattern::recvSelf - failed adding NodalLoad tagged " << theNode->getTag() << " into LP!\n"; return -3; } loc+=2; } } // // now we rebuild the ElementalLoads .. same as NodalLoads above .. see comments above // if (numEle != 0) { ID eleData(2*numEle); if (theChannel.recvID(dbEle, currentGeoTag, eleData) < 0) { opserr << "LoadPattern::recvSelf - channel failed to recv the EleLoad ID\n"; return -2; } int loc = 0; for (int i=0; i<numEle; i++) { int classTag = eleData(loc); int dbTag = eleData(loc+1); ElementalLoad *theEle = theBroker.getNewElementalLoad(classTag); if (theEle == 0) { opserr << "LoadPattern::recv - cannot create ElementalLoad with classTag " << classTag << endln; return -2; } theEle->setDbTag(dbTag); if (theEle->recvSelf(cTag, theChannel, theBroker) < 0) { opserr << "LoadPattern::recvSelf - Ele with dbTag " << dbTag << " failed in recvSelf\n"; return -2; } if (this->addElementalLoad(theEle) == false) { opserr << "LoadPattern::recvSelf - could not add Ele with tag " << theEle->getTag() << " into LP!\n"; return -3; } loc+=2; } } // // now we rebuild the SP_Constraints .. same as nodes above .. see above if can't understand!! // if (numSPs != 0) { ID spData(2*numSPs); if (theChannel.recvID(dbSPs, currentGeoTag, spData) < 0) { opserr << "LoadPattern::recvSelf - channel failed to recv the SP_Constraints ID\n"; return -2; } int loc = 0; for (int i=0; i<numSPs; i++) { int classTag = spData(loc); int dbTag = spData(loc+1); SP_Constraint *theSP = theBroker.getNewSP(classTag); if (theSP == 0) { opserr << "LoadPattern::recv - cannot create SP_Constraint with classTag " << classTag << endln; return -2; } theSP->setDbTag(dbTag); if (theSP->recvSelf(cTag, theChannel, theBroker) < 0) { opserr << "LoadPattern::recvSelf - SP_Constraint with dbTag " << dbTag << " failed in recvSelf\n"; return -2; } if (this->addSP_Constraint(theSP) == false) { opserr << "LoadPattern::recvSelf - could not add SP_Constraint with tag " << theSP->getTag() << " into LP!\n"; return -3; } loc+=2; } } // now set the load pattern db count currentGeoTag = lpData(0); lastGeoSendTag = currentGeoTag; } else { if (theSeries != 0) if (theSeries->recvSelf(cTag, theChannel, theBroker) < 0) { opserr << "LoadPattern::recvSelf - the TimeSeries failed to recv\n"; return -3; } NodalLoad *theNode; NodalLoadIter &theNodes = this->getNodalLoads(); while ((theNode = theNodes()) != 0) { if (theNode->recvSelf(cTag, theChannel, theBroker) < 0) { opserr << "LoadPattern::recvSelf - node with tag " << theNode->getTag() << " failed in recvSelf\n"; return -7; } } ElementalLoad *theEle; ElementalLoadIter &theElements = this->getElementalLoads(); while ((theEle = theElements()) != 0) { if (theEle->recvSelf(cTag, theChannel, theBroker) < 0) { opserr << "LoadPattern::recvSelf - element with tag " << theEle->getTag() << " failed in recvSelf\n"; return -8; } } SP_Constraint *theSP; SP_ConstraintIter &theSPs = this->getSPs(); while ((theSP = theSPs()) != 0) { if (theSP->recvSelf(cTag, theChannel, theBroker) < 0) { opserr << "LoadPattern::recvSelf - SP_Constraint tagged " << theSP->getTag() << " failed recvSelf\n"; return -9; } } } // if we get here we are successfull return 0; }
int BasicGFunEvaluator::elementTclVariable(int eleNumber, char* varName, char* inString) { // now obtain the information directly from domain without creating recorder files Element *theElement = theOpenSeesDomain->getElement(eleNumber); if (theElement == 0) { opserr << "GFunEvaluator::elementTclVariable -- element with tag " << eleNumber << " not found in OpenSees Domain" << endln; return 0; } int rowNumber; // index into vector containing element response const int argvLength = 20; const int argcMax = 10; char workspace[argcMax*argvLength]; char *argv[argcMax]; for (int i = 0; i < argcMax; i++) argv[i] = &workspace[i*argvLength]; int argc = 0; char restString[100]; strcpy(restString, inString); if ( strncmp(restString, "section",7) == 0) { int sectionNumber; sscanf(restString,"section_%i_%s", §ionNumber, restString); strcpy(argv[0], "section"); sprintf(argv[1], "%d", sectionNumber); if ( strncmp(restString, "force",5) == 0) { sscanf(restString,"force_%i", &rowNumber); strcpy(argv[2], "force"); sprintf(argv[3], "%d", rowNumber); argc = 4; } else if ( strncmp(restString, "deformation",11) == 0) { sscanf(restString,"deformation_%i", &rowNumber); strcpy(argv[2], "deformation"); sprintf(argv[3], "%d", rowNumber); argc = 4; } else if ( strncmp(restString, "fiber",5) == 0) { int ya, yb, za, zb; sscanf(restString,"fiber_%i_%i_%i_%i_%s", &ya, &yb, &za, &zb, restString); strcpy(argv[2],"fiber"); sprintf(argv[3],"%d.%d", ya, yb); sprintf(argv[4],"%d.%d", za, zb); if (strncmp(restString,"stress",6)==0) { strcpy(argv[5],"stress"); rowNumber = 1; argc = 6; } else if (strncmp(restString,"strain",6)==0) { strcpy(argv[5],"strain"); rowNumber = 2; argc = 6; } else { opserr << "ERROR in syntax of limit-state function for element response quantity." << endln; } } } else { // should work for any user input response quantity type (as long as element supports it) char responseType[30] = ""; char* tokstr = strtok(restString,"_"); strcpy(responseType,tokstr); tokstr = strtok(NULL,"_"); if (tokstr != NULL) rowNumber = atoi(tokstr); strcpy(argv[0], responseType); sprintf(argv[1], "%d", rowNumber); argc = 2; } char arrName[100]; sprintf(arrName,"%i,%s",eleNumber,inString); opserr << "var = " << varName << " and array = " << arrName << endln; // add the element get and set response DummyStream theHandler; Response *theResponse; theResponse = theElement->setResponse((const char **)argv, argc, theHandler); double gFunValue = 0.0; if (theResponse != 0) { theResponse->getResponse(); Information &eleInfo = theResponse->getInformation(); const Vector &eleData = eleInfo.getData(); if (eleData.Size() > 0) gFunValue = eleData(rowNumber-1); // C-index delete theResponse; } // set tcl variable if (Tcl_SetVar2Ex(theTclInterp,varName,arrName,Tcl_NewDoubleObj(gFunValue),TCL_LEAVE_ERR_MSG) == NULL) { opserr << "GFunEvaluator::elementTclVariable -- SetVar error" << endln; opserr << theTclInterp->result << endln; return -1; } return 0; }