void MaterialStageParameter::setDomain(Domain *theDomain) { Element *theEle; ElementIter &theEles = theDomain->getElements(); int theResult = -1; const char *theString[2];// = new const char*[2]; char parameterName[21]; char materialIdTag[10]; sprintf(parameterName,"updateMaterialStage"); sprintf(materialIdTag,"%d",theMaterialTag); theString[0] = parameterName; theString[1] = materialIdTag; // note because of the way this parameter is updated only need to find one in the domain while (((theEle = theEles()) != 0) && (theResult == -1)) { theResult = theEle->setParameter(theString, 2, *this); } if (theResult == -1) opserr << "WARNING: MaterialStageParameter::setDomain() - no effect with material tag " << theMaterialTag << endln; theResult = 0; return; }
int AlphaOSGeneralized::formElementResidual(void) { // calculate Residual Force AnalysisModel *theModel = this->getAnalysisModel(); LinearSOE *theSOE = this->getLinearSOE(); // loop through the FE_Elements and add the residual FE_Element *elePtr; FE_EleIter &theEles = theModel->getFEs(); while((elePtr = theEles()) != 0) { if (theSOE->addB(elePtr->getResidual(this), elePtr->getID()) < 0) { opserr << "WARNING AlphaOSGeneralized::formElementResidual -"; opserr << " failed in addB for ID " << elePtr->getID(); return -1; } if (alphaF < 1.0) { if (statusFlag == CURRENT_TANGENT) { if (theSOE->addB(elePtr->getK_Force(*Ut-*Upt), elePtr->getID(), alphaF-1.0) < 0) { opserr << "WARNING AlphaOSGeneralized::formElementResidual -"; opserr << " failed in addB for ID " << elePtr->getID(); return -2; } } else if (statusFlag == INITIAL_TANGENT) { if (theSOE->addB(elePtr->getKi_Force(*Ut-*Upt), elePtr->getID(), alphaF-1.0) < 0) { opserr << "WARNING AlphaOSGeneralized::formElementResidual -"; opserr << " failed in addB for ID " << elePtr->getID(); return -2; } } } } return 0; }
void BandArpackSolver::myMv(int n, double *v, double *result) { Vector x(v, n); Vector y(result,n); y.Zero(); AnalysisModel *theAnalysisModel = theSOE->theModel; // loop over the FE_Elements FE_Element *elePtr; FE_EleIter &theEles = theAnalysisModel->getFEs(); while((elePtr = theEles()) != 0) { const Vector &b = elePtr->getM_Force(x, 1.0); y.Assemble(b, elePtr->getID(), 1.0); } // loop over the DOF_Groups DOF_Group *dofPtr; DOF_GrpIter &theDofs = theAnalysisModel->getDOFs(); Integrator *theIntegrator = 0; while ((dofPtr = theDofs()) != 0) { const Vector &a = dofPtr->getM_Force(x,1.0); y.Assemble(a,dofPtr->getID(),1.0); } }
void XC::MatParameter::setDomain(Domain *theDomain) { Element *theEle; ElementIter &theEles = theDomain->getElements(); int theResult = -1; std::vector<std::string> theString; char materialIdTag[10]; sprintf(materialIdTag,"%d",theMaterialTag); theString[0] = theParameterName; theString[1] = materialIdTag; // note because of the way this parameter is updated only need to find one in the domain while((theEle = theEles()) != 0) { int result = theEle->setParameter(theString,*this); if(result != -1) theResult = result; } if(theResult == -1) std::cerr << "MatParameter::setDomain(Domain *theDomain) - NO RESULT\n"; }
int IncrementalIntegrator::doMv(const Vector &v, Vector &res) { int n = v.Size(); if (isDiagonal == true) { for (int i=0; i<n; i++) res[i] = diagMass[i]*v[i]; return 0; } res.Zero(); // loop over the FE_Elements FE_Element *elePtr; FE_EleIter &theEles = theAnalysisModel->getFEs(); while((elePtr = theEles()) != 0) { const Vector &b = elePtr->getM_Force(v, 1.0); res.Assemble(b, elePtr->getID(), 1.0); } // loop over the DOF_Groups DOF_Group *dofPtr; DOF_GrpIter &theDofs = theAnalysisModel->getDOFs(); while ((dofPtr = theDofs()) != 0) { const Vector &a = dofPtr->getM_Force(v, 1.0); res.Assemble(a, dofPtr->getID(), 1.0); } return 0; }
char *theElementsToJson(char *strptr) { ElementIter &theEles = theDomain.getElements(); Element *theEle; const ID *nids = NULL; char buffer[40]; int size; int ne = theDomain.getNumElements(); int j, eid; sprintf(buffer, "\"theElements\":{"); strcat(strptr, buffer); j = 0; while ((theEle = theEles()) != 0) { j++; nids = &(theEle->getExternalNodes()); eid = theEle->getTag(); size = nids->Size(); sprintf(buffer, "\"%d\":", eid); strcat(strptr, buffer); strcat(strptr, theEle->toJSON()); if (j < ne) { strcat(strptr, ","); } } strcat(strptr, "}"); return strptr; }
int PFEMIntegrator::commitSensitivity(int gradNum, int numGrads) { // Loop through the FE_Elements and set unconditional sensitivities AnalysisModel *theAnalysisModel = this->getAnalysisModel(); FE_Element *elePtr; FE_EleIter &theEles = theAnalysisModel->getFEs(); while((elePtr = theEles()) != 0) { elePtr->commitSensitivity(gradNum, numGrads); } return 0; }
int OPS_PFEMElement2D(Domain& theDomain, const ID& elenodes, ID& eletags) { int numdata = OPS_GetNumRemainingInputArgs(); if(numdata < 4) { opserr<<"WARNING: insufficient number of arguments\n"; return 0; } // rho, mu, b1, b2, (thickness, kappa, lumped) numdata = OPS_GetNumRemainingInputArgs(); if(numdata > 7) numdata = 7; double data[7] = {0,0,0,0,1.0,-1,1}; if(OPS_GetDoubleInput(&numdata,data) < 0) return 0; // create elements ElementIter& theEles = theDomain.getElements(); Element* theEle = theEles(); int currTag = 0; if (theEle != 0) { currTag = theEle->getTag(); } eletags.resize(elenodes.Size()/3); for (int i=0; i<eletags.Size(); i++) { theEle = new PFEMElement2D(--currTag,elenodes(3*i),elenodes(3*i+1),elenodes(3*i+2), data[0],data[1],data[2],data[3],data[4],data[5],data[6]); if (theEle == 0) { opserr<<"WARNING: run out of memory for creating element\n"; return -1; } if (theDomain.addElement(theEle) == false) { opserr<<"WARNING: failed to add element to domain\n"; delete theEle; return -1; } eletags(i) = currTag; } return 0; }
int DirectIntegrationAnalysis::eigen(int numMode, bool generalized) { if (theAnalysisModel == 0 || theEigenSOE == 0) { opserr << "WARNING DirectIntegrationAnalysis::eigen() - no EigenSOE has been set\n"; return -1; } int result = 0; Domain *the_Domain = this->getDomainPtr(); result = theAnalysisModel->eigenAnalysis(numMode, generalized); int stamp = the_Domain->hasDomainChanged(); if (stamp != domainStamp) { domainStamp = stamp; result = this->domainChanged(); if (result < 0) { opserr << "DirectIntegrationAnalysis::eigen() - domainChanged failed"; return -1; } } // // zero A and M // theEigenSOE->zeroA(); theEigenSOE->zeroM(); // // form K // FE_EleIter &theEles = theAnalysisModel->getFEs(); FE_Element *elePtr; while((elePtr = theEles()) != 0) { elePtr->zeroTangent(); elePtr->addKtToTang(1.0); if (theEigenSOE->addA(elePtr->getTangent(0), elePtr->getID()) < 0) { opserr << "WARNING DirectIntegrationAnalysis::eigen() -"; opserr << " failed in addA for ID " << elePtr->getID(); result = -2; } } // // if generalized is true, form M // if (generalized == true) { int result = 0; FE_EleIter &theEles2 = theAnalysisModel->getFEs(); while((elePtr = theEles2()) != 0) { elePtr->zeroTangent(); elePtr->addMtoTang(1.0); if (theEigenSOE->addM(elePtr->getTangent(0), elePtr->getID()) < 0) { opserr << "WARNING DirectIntegrationAnalysis::eigen() -"; opserr << " failed in addA for ID " << elePtr->getID(); result = -2; } } DOF_Group *dofPtr; DOF_GrpIter &theDofs = theAnalysisModel->getDOFs(); while((dofPtr = theDofs()) != 0) { dofPtr->zeroTangent(); dofPtr->addMtoTang(1.0); if (theEigenSOE->addM(dofPtr->getTangent(0),dofPtr->getID()) < 0) { opserr << "WARNING DirectIntegrationAnalysis::eigen() -"; opserr << " failed in addM for ID " << dofPtr->getID(); result = -3; } } } // // solve for the eigen values & vectors // if (theEigenSOE->solve(numMode, generalized) < 0) { opserr << "WARNING DirectIntegrationAnalysis::eigen() - EigenSOE failed in solve()\n"; return -4; } // // now set the eigenvalues and eigenvectors in the model // theAnalysisModel->setNumEigenvectors(numMode); Vector theEigenvalues(numMode); for (int i = 1; i <= numMode; i++) { theEigenvalues[i-1] = theEigenSOE->getEigenvalue(i); theAnalysisModel->setEigenvector(i, theEigenSOE->getEigenvector(i)); } theAnalysisModel->setEigenvalues(theEigenvalues); return 0; }
int OPS_ElasticBeam2d(Domain& theDomain, const ID& elenodes, ID& eletags) { if(OPS_GetNumRemainingInputArgs() < 4) { opserr<<"insufficient arguments:A,E,Iz,transfTag\n"; return -1; } // inputs: double data[3]; int numData = 3; if(OPS_GetDoubleInput(&numData,&data[0]) < 0) return -1; numData = 1; int transfTag; if(OPS_GetIntInput(&numData,&transfTag) < 0) return -1; // options double mass = 0.0, alpha=0.0, depth=0.0; int cMass = 0; while(OPS_GetNumRemainingInputArgs() > 0) { std::string type = OPS_GetString(); if(type == "-alpha") { if(OPS_GetNumRemainingInputArgs() > 0) { if(OPS_GetDoubleInput(&numData,&alpha) < 0) return -1; } } else if(type == "-depth") { if(OPS_GetNumRemainingInputArgs() > 0) { if(OPS_GetDoubleInput(&numData,&depth) < 0) return -1; } } else if(type == "-mass") { if(OPS_GetNumRemainingInputArgs() > 0) { if(OPS_GetDoubleInput(&numData,&mass) < 0) return -1; } } else if(type == "-cMass") { cMass = 1; } } // check transf CrdTransf* theTransf = OPS_getCrdTransf(transfTag); if(theTransf == 0) { opserr<<"coord transfomration not found\n"; return -1; } // create elements ElementIter& theEles = theDomain.getElements(); Element* theEle = theEles(); int currTag = 0; if (theEle != 0) { currTag = theEle->getTag(); } eletags.resize(elenodes.Size()/2); for (int i=0; i<elenodes.Size()/2; i++) { theEle = new ElasticBeam2d(--currTag,data[0],data[1],data[2],elenodes(2*i),elenodes(2*i+1), *theTransf,alpha,depth,mass,cMass); if (theEle == 0) { opserr<<"WARING: run out of memory for creating element\n"; return -1; } if (theDomain.addElement(theEle) == false) { opserr<<"WARNING: failed to add element to domain\n"; delete theEle; return -1; } eletags(i) = currTag; } return 0; }
void ArpackSolver::myMv(int n, double *v, double *result) { Vector x(v, n); Vector y(result,n); bool mDiagonal = theArpackSOE->mDiagonal; if (mDiagonal == true) { int Msize = theArpackSOE->Msize; double *M = theArpackSOE->M; /* for output DataFileStream dataStream("M.txt"); dataStream.open(); for (int i=0; i<n; i++) dataStream << M[i] << endln; dataStream.close(); */ if (n <= Msize) { for (int i=0; i<n; i++) result[i] = M[i]*v[i]; } else { opserr << "ArpackSolver::myMv() n > Msize!\n"; return; } } else { y.Zero(); AnalysisModel *theAnalysisModel = theArpackSOE->theModel; // loop over the FE_Elements FE_Element *elePtr; FE_EleIter &theEles = theAnalysisModel->getFEs(); while((elePtr = theEles()) != 0) { const Vector &b = elePtr->getM_Force(x, 1.0); y.Assemble(b, elePtr->getID(), 1.0); } // loop over the DOF_Groups DOF_Group *dofPtr; DOF_GrpIter &theDofs = theAnalysisModel->getDOFs(); while ((dofPtr = theDofs()) != 0) { const Vector &a = dofPtr->getM_Force(x,1.0); y.Assemble(a, dofPtr->getID(), 1.0); } } // if paallel we have to merge the results int processID = theArpackSOE->processID; if (processID != -1) { Channel **theChannels = theArpackSOE->theChannels; int numChannels = theArpackSOE->numChannels; if (processID != 0) { theChannels[0]->sendVector(0, 0, y); theChannels[0]->recvVector(0, 0, y); } else { Vector other(workArea, n); // recv contribution from remote & add for (int i=0; i<numChannels; i++) { theChannels[i]->recvVector(0,0,other); y += other; } // send result back for (int i=0; i<numChannels; i++) { theChannels[i]->sendVector(0,0,y); } } } }
int MeshRegion::setNodes(const ID &theNods) { // destroy the old lists if (theNodes != 0) delete theNodes; if (theElements != 0) delete theElements; // // create new element & node lists // // create empty lists Domain *theDomain = this->getDomain(); if (theDomain == 0) { opserr << "MeshRegion::setNodes() - no domain yet set\n"; return -1; } int numNodes = theNods.Size(); theNodes = new ID(0, numNodes); theElements = new ID(0, numNodes); if (theNodes == 0 || theElements == 0) { opserr << "MeshRegion::setElements() - ran out of memory\n"; return -1; } // add nodes to the node list if in the domain int loc = 0; for (int i=0; i<numNodes; i++) { int nodeTag = theNods(i); Node *theNode = theDomain->getNode(nodeTag); if (theNode != 0) { if (theNodes->getLocation(nodeTag) < 0) (*theNodes)[loc++] = nodeTag; } } // now loop over the ele to create the ele list // NOTE - ele added to list if all it's nodes are in the region loc = 0; ElementIter &theEles = theDomain->getElements(); Element *theEle; // loop over all ele while ((theEle = theEles()) != 0) { int eleTag = theEle->getTag(); // check to see if all external nodes in node list bool in = true; const ID &theEleNodes = theEle->getExternalNodes(); int numNodes = theEleNodes.Size(); for (int i=0; i<numNodes; i++) { int nodeTag = theEleNodes(i); if (theNodes->getLocation(nodeTag) < 0) { in = false; i = numNodes; } } // if they are all in the node list add the ele to ele list if (in == true) (*theElements)[loc++] = eleTag; } return 0; }
int OPS_Tri31(Domain& theDomain, const ID& elenodes, ID& eletags) { // get inputs int numRemainingInputArgs = OPS_GetNumRemainingInputArgs(); if (numRemainingInputArgs < 3) { opserr << "Invalid #args, want: thk? type? matTag? <pressure? rho? b1? b2?>\n"; return -1; } int matID; double thk; char *theType; double dData[4]; dData[0] = 0.0; dData[1] = 0.0; dData[2] = 0.0; dData[3] = 0.0; int numData = 1; if (OPS_GetDoubleInput(&numData, &thk) != 0) { opserr << "WARNING invalid thickness data: element Tri31 \n"; return -1; } theType = (char*)OPS_GetString(); numData = 1; if (OPS_GetIntInput(&numData, &matID) != 0) { opserr << "WARNING invalid integer data: element Tri31\n"; return -1; } NDMaterial *theMaterial = OPS_getNDMaterial(matID); if (theMaterial == 0) { opserr << "WARNING element Tri31 \n"; opserr << " Material: " << matID << "not found\n"; return -1; } if (OPS_GetNumRemainingInputArgs() >= 4) { numData = 4; if (OPS_GetDoubleInput(&numData, &dData[0]) != 0) { opserr << "WARNING invalid optional data: element Tri31\n"; return -1; } } // create elements ElementIter& theEles = theDomain.getElements(); Element* theEle = theEles(); int currTag = 0; if (theEle != 0) { currTag = theEle->getTag(); } eletags.resize(elenodes.Size()/3); for (int i=0; i<eletags.Size(); i++) { theEle = new Tri31(--currTag,elenodes(3*i),elenodes(3*i+1),elenodes(3*i+2), *theMaterial, theType, thk, dData[0], dData[1], dData[2], dData[3]); if (theEle == 0) { opserr<<"WARNING: run out of memory for creating element\n"; return -1; } if (theDomain.addElement(theEle) == false) { opserr<<"WARNING: failed to add element to domain\n"; delete theEle; return -1; } eletags(i) = currTag; } return 0; }
int PFEMIntegrator::formSensitivityRHS(int passedGradNumber) { sensitivityFlag = 1; // Set a couple of data members gradNumber = passedGradNumber; // Get pointer to the SOE LinearSOE *theSOE = this->getLinearSOE(); // Get the analysis model AnalysisModel *theModel = this->getAnalysisModel(); // Randomness in external load (including randomness in time series) // Get domain Domain *theDomain = theModel->getDomainPtr(); // Loop through nodes to zero the unbalaced load Node *nodePtr; NodeIter &theNodeIter = theDomain->getNodes(); while ((nodePtr = theNodeIter()) != 0) nodePtr->zeroUnbalancedLoad(); // Loop through load patterns to add external load sensitivity LoadPattern *loadPatternPtr; LoadPatternIter &thePatterns = theDomain->getLoadPatterns(); double time; while((loadPatternPtr = thePatterns()) != 0) { time = theDomain->getCurrentTime(); loadPatternPtr->applyLoadSensitivity(time); } // Randomness in element/material contributions // Loop through FE elements FE_Element *elePtr; FE_EleIter &theEles = theModel->getFEs(); while((elePtr = theEles()) != 0) { theSOE->addB( elePtr->getResidual(this), elePtr->getID() ); } // Loop through DOF groups (IT IS IMPORTANT THAT THIS IS DONE LAST!) DOF_Group *dofPtr; DOF_GrpIter &theDOFs = theModel->getDOFs(); while((dofPtr = theDOFs()) != 0) { theSOE->addB( dofPtr->getUnbalance(this), dofPtr->getID() ); } // Reset the sensitivity flag sensitivityFlag = 0; return 0; }