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 <LagrangeConstraintHandler.h>
00035 #include <stdlib.h>
00036
00037 #include <AnalysisModel.h>
00038 #include <Domain.h>
00039 #include <FE_Element.h>
00040 #include <DOF_Group.h>
00041 #include <Node.h>
00042 #include <Element.h>
00043 #include <NodeIter.h>
00044 #include <ElementIter.h>
00045 #include <SP_ConstraintIter.h>
00046 #include <SP_Constraint.h>
00047 #include <MP_ConstraintIter.h>
00048 #include <MP_Constraint.h>
00049 #include <Integrator.h>
00050 #include <ID.h>
00051 #include <Subdomain.h>
00052 #include <Channel.h>
00053 #include <FEM_ObjectBroker.h>
00054 #include <LagrangeDOF_Group.h>
00055 #include <LagrangeSP_FE.h>
00056 #include <LagrangeMP_FE.h>
00057
00058
00059 LagrangeConstraintHandler::LagrangeConstraintHandler(double sp, double mp)
00060 :ConstraintHandler(HANDLER_TAG_LagrangeConstraintHandler),
00061 alphaSP(sp), alphaMP(mp),
00062 theFEs(0), theDOFs(0),numFE(0),numDOF(0)
00063 {
00064
00065 }
00066
00067 LagrangeConstraintHandler::~LagrangeConstraintHandler()
00068 {
00069 for (int i=0; i<numFE; i++)
00070 if (theFEs[i] != 0)
00071 delete theFEs[i];
00072
00073 for (int j=0; j<numDOF; j++)
00074 if (theDOFs[j] != 0)
00075 delete theDOFs[j];
00076
00077
00078 if (theFEs != 0) delete [] theFEs;
00079 if (theDOFs != 0) delete [] theDOFs;
00080 }
00081
00082 int
00083 LagrangeConstraintHandler::handle(const ID *nodesLast)
00084 {
00085
00086 Domain *theDomain = this->getDomainPtr();
00087 AnalysisModel *theModel = this->getAnalysisModelPtr();
00088 Integrator *theIntegrator = this->getIntegratorPtr();
00089
00090 if ((theDomain == 0) || (theModel == 0) || (theIntegrator == 0)) {
00091 cerr << "WARNING LagrangeConstraintHandler::handle() - ";
00092 cerr << " setLinks() has not been called\n";
00093 return -1;
00094 }
00095
00096
00097
00098
00099
00100 int numConstraints = 0;
00101 SP_ConstraintIter &theSPss = theDomain->getDomainAndLoadPatternSPs();
00102 SP_Constraint *spPtr;
00103 while ((spPtr = theSPss()) != 0)
00104 numConstraints++;
00105
00106 numConstraints += theDomain->getNumMPs();
00107 numFE = theDomain->getNumElements() + numConstraints;
00108 numDOF = theDomain->getNumNodes() + numConstraints;
00109
00110
00111 if ((numFE <= 0) || ((theFEs = new FE_Element *[numFE]) == 0)) {
00112 cerr << "WARNING LagrangeConstraintHandler::handle() - ";
00113 cerr << "ran out of memory for FE_elements";
00114 cerr << " array of size " << numFE << endl;
00115 return -2;
00116 }
00117 int i;
00118 for (i=0; i<numFE; i++) theFEs[i] = 0;
00119
00120
00121 if ((numDOF <= 0) || ((theDOFs = new DOF_Group *[numDOF]) == 0)) {
00122 cerr << "WARNING LagrangeConstraintHandler::handle() - ";
00123 cerr << "ran out of memory for DOF_Groups";
00124 cerr << " array of size " << numDOF << endl;
00125 return -3;
00126 }
00127 for (i=0; i<numDOF; i++) theDOFs[i] = 0;
00128
00129
00130
00131 NodeIter &theNod = theDomain->getNodes();
00132 Node *nodPtr;
00133 MP_Constraint *mpPtr;
00134 DOF_Group *dofPtr;
00135
00136 int numDofGrp = 0;
00137 int count3 = 0;
00138 int countDOF =0;
00139 while ((nodPtr = theNod()) != 0) {
00140 if ((dofPtr = new DOF_Group(numDofGrp, nodPtr)) == 0) {
00141 cerr << "WARNING LagrangeConstraintHandler::handle() ";
00142 cerr << "- ran out of memory";
00143 cerr << " creating DOF_Group " << i << endl;
00144 return -4;
00145 }
00146
00147
00148 const ID &id = dofPtr->getID();
00149 for (int j=0; j < id.Size(); j++) {
00150 dofPtr->setID(j,-2);
00151 countDOF++;
00152 }
00153
00154 nodPtr->setDOF_GroupPtr(dofPtr);
00155 theDOFs[numDofGrp++] = dofPtr;
00156 theModel->addDOF_Group(dofPtr);
00157 }
00158
00159
00160 ElementIter &theEle = theDomain->getElements();
00161 Element *elePtr;
00162
00163 int numFeEle = 0;
00164 FE_Element *fePtr;
00165 while ((elePtr = theEle()) != 0) {
00166 if ((fePtr = new FE_Element(elePtr)) == 0) {
00167 cerr << "WARNING LagrangeConstraintHandler::handle()";
00168 cerr << " - ran out of memory";
00169 cerr << " creating FE_Element " << elePtr->getTag() << endl;
00170 return -5;
00171 }
00172
00173 theFEs[numFeEle++] = fePtr;
00174
00175 theModel->addFE_Element(fePtr);
00176 if (elePtr->isSubdomain() == true) {
00177 Subdomain *theSub = (Subdomain *)elePtr;
00178 theSub->setFE_ElementPtr(fePtr);
00179 }
00180 }
00181
00182
00183
00184
00185
00186 SP_ConstraintIter &theSPs = theDomain->getDomainAndLoadPatternSPs();
00187 while ((spPtr = theSPs()) != 0) {
00188 if ((dofPtr = new LagrangeDOF_Group(numDofGrp, *spPtr)) == 0) {
00189 cerr << "WARNING LagrangeConstraintHandler::handle()";
00190 cerr << " - ran out of memory";
00191 cerr << " creating LagrangeDOFGroup " << endl;
00192 return -5;
00193 }
00194 const ID &id = dofPtr->getID();
00195 for (int j=0; j < id.Size(); j++) {
00196 dofPtr->setID(j,-2);
00197 countDOF++;
00198 }
00199
00200 theDOFs[numDofGrp++] = dofPtr;
00201 theModel->addDOF_Group(dofPtr);
00202
00203 if ((fePtr = new LagrangeSP_FE(*theDomain, *spPtr,
00204 *dofPtr, alphaSP)) == 0) {
00205 cerr << "WARNING LagrangeConstraintHandler::handle()";
00206 cerr << " - ran out of memory";
00207 cerr << " creating LagrangeSP_FE " << endl;
00208 return -5;
00209 }
00210 theFEs[numFeEle++] = fePtr;
00211 theModel->addFE_Element(fePtr);
00212 }
00213
00214
00215
00216
00217 MP_ConstraintIter &theMPs = theDomain->getMPs();
00218 while ((mpPtr = theMPs()) != 0) {
00219 if ((dofPtr = new LagrangeDOF_Group(numDofGrp, *mpPtr)) == 0) {
00220 cerr << "WARNING LagrangeConstraintHandler::handle()";
00221 cerr << " - ran out of memory";
00222 cerr << " creating LagrangeDOFGroup " << endl;
00223 return -5;
00224 }
00225 const ID &id = dofPtr->getID();
00226 for (int j=0; j < id.Size(); j++) {
00227 dofPtr->setID(j,-2);
00228 countDOF++;
00229 }
00230
00231 theDOFs[numDofGrp++] = dofPtr;
00232 theModel->addDOF_Group(dofPtr);
00233
00234 if ((fePtr = new LagrangeMP_FE(*theDomain, *mpPtr,
00235 *dofPtr, alphaMP)) == 0) {
00236 cerr << "WARNING LagrangeConstraintHandler::handle()";
00237 cerr << " - ran out of memory";
00238 cerr << " creating LagrangeMP_FE " << endl;
00239 return -5;
00240 }
00241
00242 theFEs[numFeEle++] = fePtr;
00243 theModel->addFE_Element(fePtr);
00244 }
00245
00246 theModel->setNumEqn(countDOF);
00247
00248
00249
00250
00251 if (nodesLast != 0)
00252 for (i=0; i<nodesLast->Size(); i++) {
00253 int nodeID = (*nodesLast)(i);
00254 Node *nodPtr = theDomain->getNode(nodeID);
00255 if (nodPtr != 0) {
00256 dofPtr = nodPtr->getDOF_GroupPtr();
00257
00258 const ID &id = dofPtr->getID();
00259
00260 for (int j=0; j < id.Size(); j++)
00261 if (id(j) == -2) {
00262 dofPtr->setID(j,-3);
00263 count3++;
00264 } else {
00265 cerr << "WARNING LagrangeConstraintHandler::handle() ";
00266 cerr << " - boundary sp constraint in subdomain";
00267 cerr << " this should not be - results suspect \n";
00268 }
00269 }
00270 }
00271
00272 return count3;
00273 }
00274
00275
00276 void
00277 LagrangeConstraintHandler::clearAll(void)
00278 {
00279
00280 for (int i=0; i<numFE; i++)
00281 if (theFEs[i] != 0)
00282 delete theFEs[i];
00283
00284 for (int j=0; j<numDOF; j++)
00285 if (theDOFs[j] != 0)
00286 delete theDOFs[j];
00287
00288
00289 if (theFEs != 0) delete [] theFEs;
00290 if (theDOFs != 0) delete [] theDOFs;
00291
00292
00293 numDOF = 0;
00294 numFE = 0;
00295 theFEs = 0;
00296 theDOFs = 0;
00297
00298
00299 Domain *theDomain = this->getDomainPtr();
00300 if (theDomain == 0)
00301 return;
00302
00303 NodeIter &theNod = theDomain->getNodes();
00304 Node *nodPtr;
00305 while ((nodPtr = theNod()) != 0)
00306 nodPtr->setDOF_GroupPtr(0);
00307 }
00308
00309 int
00310 LagrangeConstraintHandler::sendSelf(int cTag, Channel &theChannel)
00311 {
00312 Vector data(2);
00313 int result = 0;
00314 data(0) = alphaSP;
00315 data(1) = alphaMP;
00316 result = theChannel.sendVector(this->getDbTag(), cTag, data);
00317 if (result != 0)
00318 cerr << "LagrangeConstraintHandler::sendSelf() - error sending Vector\n";
00319 return result;
00320 }
00321
00322 int
00323 LagrangeConstraintHandler::recvSelf(int cTag,
00324 Channel &theChannel,
00325 FEM_ObjectBroker &theBroker)
00326 {
00327 Vector data(2);
00328 int result = 0;
00329 result = theChannel.sendVector(this->getDbTag(), cTag, data);
00330 alphaSP = data(0);
00331 alphaMP = data(1);
00332 if (result != 0)
00333 cerr << "LagrangeConstraintHandler::recvSelf() - error receiving Vector\n";
00334 return result;
00335 }
00336