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 #include <PenaltyConstraintHandler.h>
00033 #include <stdlib.h>
00034
00035 #include <AnalysisModel.h>
00036 #include <Domain.h>
00037 #include <FE_Element.h>
00038 #include <DOF_Group.h>
00039 #include <Node.h>
00040 #include <Element.h>
00041 #include <NodeIter.h>
00042 #include <ElementIter.h>
00043 #include <SP_ConstraintIter.h>
00044 #include <SP_Constraint.h>
00045 #include <MP_ConstraintIter.h>
00046 #include <MP_Constraint.h>
00047 #include <Integrator.h>
00048 #include <ID.h>
00049 #include <Subdomain.h>
00050 #include <Channel.h>
00051 #include <FEM_ObjectBroker.h>
00052 #include <PenaltySP_FE.h>
00053 #include <PenaltyMP_FE.h>
00054
00055
00056 PenaltyConstraintHandler::PenaltyConstraintHandler(double sp, double mp)
00057 :ConstraintHandler(HANDLER_TAG_PenaltyConstraintHandler),
00058 alphaSP(sp), alphaMP(mp)
00059 {
00060
00061 }
00062
00063 PenaltyConstraintHandler::~PenaltyConstraintHandler()
00064 {
00065
00066 }
00067
00068 int
00069 PenaltyConstraintHandler::handle(const ID *nodesLast)
00070 {
00071
00072 Domain *theDomain = this->getDomainPtr();
00073 AnalysisModel *theModel = this->getAnalysisModelPtr();
00074 Integrator *theIntegrator = this->getIntegratorPtr();
00075
00076 if ((theDomain == 0) || (theModel == 0) || (theIntegrator == 0)) {
00077 opserr << "WARNING PenaltyConstraintHandler::handle() - ";
00078 opserr << " setLinks() has not been called\n";
00079 return -1;
00080 }
00081
00082
00083
00084
00085 int numSPs = 0;
00086 SP_ConstraintIter &theSPs = theDomain->getDomainAndLoadPatternSPs();
00087 SP_Constraint *spPtr;
00088 while ((spPtr = theSPs()) != 0)
00089 numSPs++;
00090
00091
00092
00093 NodeIter &theNod = theDomain->getNodes();
00094 Node *nodPtr;
00095 MP_Constraint *mpPtr;
00096 DOF_Group *dofPtr;
00097
00098 int numDofGrp = 0;
00099 int count3 = 0;
00100 int countDOF =0;
00101 while ((nodPtr = theNod()) != 0) {
00102 if ((dofPtr = new DOF_Group(numDofGrp++, nodPtr)) == 0) {
00103 opserr << "WARNING PenaltyConstraintHandler::handle() ";
00104 opserr << "- ran out of memory";
00105 opserr << " creating DOF_Group " << numDofGrp << endln;
00106 return -4;
00107 }
00108
00109
00110 const ID &id = dofPtr->getID();
00111 for (int j=0; j < id.Size(); j++) {
00112 dofPtr->setID(j,-2);
00113 countDOF++;
00114 }
00115 nodPtr->setDOF_GroupPtr(dofPtr);
00116 theModel->addDOF_Group(dofPtr);
00117 }
00118
00119 theModel->setNumEqn(countDOF);
00120
00121
00122
00123
00124 if (nodesLast != 0)
00125 for (int i=0; i<nodesLast->Size(); i++) {
00126 int nodeID = (*nodesLast)(i);
00127 Node *nodPtr = theDomain->getNode(nodeID);
00128 if (nodPtr != 0) {
00129 dofPtr = nodPtr->getDOF_GroupPtr();
00130
00131 const ID &id = dofPtr->getID();
00132
00133 for (int j=0; j < id.Size(); j++)
00134 if (id(j) == -2) {
00135 dofPtr->setID(j,-3);
00136 count3++;
00137 } else {
00138 opserr << "WARNING PenaltyConstraintHandler::handle() ";
00139 opserr << " - boundary sp constraint in subdomain";
00140 opserr << " this should not be - results suspect \n";
00141 }
00142 }
00143 }
00144
00145
00146 ElementIter &theEle = theDomain->getElements();
00147 Element *elePtr;
00148
00149 int numFeEle = 0;
00150 FE_Element *fePtr;
00151 while ((elePtr = theEle()) != 0) {
00152
00153
00154
00155
00156 if (elePtr->isSubdomain() == true) {
00157 Subdomain *theSub = (Subdomain *)elePtr;
00158 if (theSub->doesIndependentAnalysis() == false) {
00159 if ((fePtr = new FE_Element(numFeEle++, elePtr)) == 0) {
00160 opserr << "WARNING PlainHandler::handle() - ran out of memory";
00161 opserr << " creating FE_Element " << elePtr->getTag() << endln;
00162 return -5;
00163 }
00164
00165 theModel->addFE_Element(fePtr);
00166 theSub->setFE_ElementPtr(fePtr);
00167
00168 }
00169
00170 } else {
00171
00172
00173 if ((fePtr = new FE_Element(numFeEle++, elePtr)) == 0) {
00174 opserr << "WARNING PlainHandler::handle() - ran out of memory";
00175 opserr << " creating FE_Element " << elePtr->getTag() << endln;
00176 return -5;
00177 }
00178
00179 theModel->addFE_Element(fePtr);
00180 }
00181 }
00182
00183
00184
00185
00186 SP_ConstraintIter &theSPss = theDomain->getDomainAndLoadPatternSPs();
00187 while ((spPtr = theSPss()) != 0) {
00188 if ((fePtr = new PenaltySP_FE(numFeEle, *theDomain, *spPtr, alphaSP)) == 0) {
00189 opserr << "WARNING PenaltyConstraintHandler::handle()";
00190 opserr << " - ran out of memory";
00191 opserr << " creating PenaltySP_FE " << endln;
00192 return -5;
00193 }
00194 theModel->addFE_Element(fePtr);
00195 numFeEle++;
00196 }
00197
00198
00199
00200
00201 MP_ConstraintIter &theMPs = theDomain->getMPs();
00202 while ((mpPtr = theMPs()) != 0) {
00203 if ((fePtr = new PenaltyMP_FE(numFeEle, *theDomain, *mpPtr, alphaMP)) == 0) {
00204 opserr << "WARNING PenaltyConstraintHandler::handle()";
00205 opserr << " - ran out of memory";
00206 opserr << " creating PenaltyMP_FE " << endln;
00207 return -5;
00208 }
00209 theModel->addFE_Element(fePtr);
00210 numFeEle++;
00211 }
00212
00213 return count3;
00214 }
00215
00216
00217 void
00218 PenaltyConstraintHandler::clearAll(void)
00219 {
00220
00221 Domain *theDomain = this->getDomainPtr();
00222 if (theDomain == 0)
00223 return;
00224
00225 NodeIter &theNod = theDomain->getNodes();
00226 Node *nodPtr;
00227 while ((nodPtr = theNod()) != 0)
00228 nodPtr->setDOF_GroupPtr(0);
00229 }
00230
00231 int
00232 PenaltyConstraintHandler::sendSelf(int cTag, Channel &theChannel)
00233 {
00234 Vector data(2);
00235 int result = 0;
00236 data(0) = alphaSP;
00237 data(1) = alphaMP;
00238 result = theChannel.sendVector(this->getDbTag(), cTag, data);
00239 if (result != 0)
00240 opserr << "PenaltyConstraintHandler::sendSelf() - error sending Vector\n";
00241 return result;
00242 }
00243
00244 int
00245 PenaltyConstraintHandler::recvSelf(int cTag,
00246 Channel &theChannel,
00247 FEM_ObjectBroker &theBroker)
00248 {
00249 Vector data(2);
00250 int result = 0;
00251 result = theChannel.recvVector(this->getDbTag(), cTag, data);
00252 alphaSP = data(0);
00253 alphaMP = data(1);
00254 if (result != 0)
00255 opserr << "PenaltyConstraintHandler::recvSelf() - error receiving Vector\n";
00256 return result;
00257 }