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 <PenaltyConstraintHandler.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 <PenaltySP_FE.h>
00055 #include <PenaltyMP_FE.h>
00056
00057
00058 PenaltyConstraintHandler::PenaltyConstraintHandler(double sp, double mp)
00059 :ConstraintHandler(HANDLER_TAG_PenaltyConstraintHandler),
00060 alphaSP(sp), alphaMP(mp),
00061 theFEs(0), theDOFs(0),numFE(0),numDOF(0)
00062 {
00063
00064 }
00065
00066 PenaltyConstraintHandler::~PenaltyConstraintHandler()
00067 {
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 PenaltyConstraintHandler::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 PenaltyConstraintHandler::handle() - ";
00092 cerr << " setLinks() has not been called\n";
00093 return -1;
00094 }
00095
00096
00097
00098
00099 int numSPs = 0;
00100 SP_ConstraintIter &theSPs = theDomain->getDomainAndLoadPatternSPs();
00101 SP_Constraint *spPtr;
00102 while ((spPtr = theSPs()) != 0)
00103 numSPs++;
00104
00105 numFE = theDomain->getNumElements() + numSPs + theDomain->getNumMPs();
00106
00107 numDOF = theDomain->getNumNodes();
00108
00109
00110 if ((numFE <= 0) || ((theFEs = new FE_Element *[numFE]) == 0)) {
00111 cerr << "WARNING PenaltyConstraintHandler::handle() - ";
00112 cerr << "ran out of memory for FE_elements";
00113 cerr << " array of size " << numFE << endl;
00114 cerr << "(if size == 0 YOU HAVE NO ELEMENTS)\n";
00115 numFE = 0;
00116 return -2;
00117 }
00118 int i;
00119 for (i=0; i<numFE; i++) theFEs[i] = 0;
00120
00121
00122 if ((numDOF <= 0) || ((theDOFs = new DOF_Group *[numDOF]) == 0)) {
00123 cerr << "WARNING PenaltyConstraintHandler::handle() - ";
00124 cerr << "ran out of memory for DOF_Groups";
00125 cerr << " array of size " << numDOF << endl;
00126 cerr << "(if size == 0 YOU HAVE NO NODES)\n";
00127 numDOF = 0;
00128 return -3;
00129 }
00130 for (i=0; i<numDOF; i++) theDOFs[i] = 0;
00131
00132
00133
00134 NodeIter &theNod = theDomain->getNodes();
00135 Node *nodPtr;
00136 MP_Constraint *mpPtr;
00137 DOF_Group *dofPtr;
00138
00139 int numDofGrp = 0;
00140 int count3 = 0;
00141 int countDOF =0;
00142 while ((nodPtr = theNod()) != 0) {
00143 if ((dofPtr = new DOF_Group(numDofGrp, nodPtr)) == 0) {
00144 cerr << "WARNING PenaltyConstraintHandler::handle() ";
00145 cerr << "- ran out of memory";
00146 cerr << " creating DOF_Group " << i << endl;
00147 return -4;
00148 }
00149
00150
00151 const ID &id = dofPtr->getID();
00152 for (int j=0; j < id.Size(); j++) {
00153 dofPtr->setID(j,-2);
00154 countDOF++;
00155 }
00156 nodPtr->setDOF_GroupPtr(dofPtr);
00157 theDOFs[numDofGrp++] = dofPtr;
00158 theModel->addDOF_Group(dofPtr);
00159 }
00160
00161 theModel->setNumEqn(countDOF);
00162
00163
00164
00165
00166 if (nodesLast != 0)
00167 for (i=0; i<nodesLast->Size(); i++) {
00168 int nodeID = (*nodesLast)(i);
00169 Node *nodPtr = theDomain->getNode(nodeID);
00170 if (nodPtr != 0) {
00171 dofPtr = nodPtr->getDOF_GroupPtr();
00172
00173 const ID &id = dofPtr->getID();
00174
00175 for (int j=0; j < id.Size(); j++)
00176 if (id(j) == -2) {
00177 dofPtr->setID(j,-3);
00178 count3++;
00179 } else {
00180 cerr << "WARNING PenaltyConstraintHandler::handle() ";
00181 cerr << " - boundary sp constraint in subdomain";
00182 cerr << " this should not be - results suspect \n";
00183 }
00184 }
00185 }
00186
00187
00188 ElementIter &theEle = theDomain->getElements();
00189 Element *elePtr;
00190
00191 int numFeEle = 0;
00192 FE_Element *fePtr;
00193 while ((elePtr = theEle()) != 0) {
00194 if ((fePtr = new FE_Element(elePtr)) == 0) {
00195 cerr << "WARNING PenaltyConstraintHandler::handle()";
00196 cerr << " - ran out of memory";
00197 cerr << " creating FE_Element " << elePtr->getTag() << endl;
00198 return -5;
00199 }
00200
00201 theFEs[numFeEle++] = fePtr;
00202
00203 theModel->addFE_Element(fePtr);
00204 if (elePtr->isSubdomain() == true) {
00205 Subdomain *theSub = (Subdomain *)elePtr;
00206 theSub->setFE_ElementPtr(fePtr);
00207 }
00208 }
00209
00210
00211
00212
00213
00214 SP_ConstraintIter &theSPss = theDomain->getDomainAndLoadPatternSPs();
00215 while ((spPtr = theSPss()) != 0) {
00216 if ((fePtr = new PenaltySP_FE(*theDomain, *spPtr, alphaSP)) == 0) {
00217 cerr << "WARNING PenaltyConstraintHandler::handle()";
00218 cerr << " - ran out of memory";
00219 cerr << " creating PenaltySP_FE " << endl;
00220 return -5;
00221 }
00222 theFEs[numFeEle++] = fePtr;
00223 theModel->addFE_Element(fePtr);
00224 }
00225
00226
00227
00228
00229 MP_ConstraintIter &theMPs = theDomain->getMPs();
00230 while ((mpPtr = theMPs()) != 0) {
00231 if ((fePtr = new PenaltyMP_FE(*theDomain, *mpPtr, alphaMP)) == 0) {
00232 cerr << "WARNING PenaltyConstraintHandler::handle()";
00233 cerr << " - ran out of memory";
00234 cerr << " creating PenaltyMP_FE " << endl;
00235 return -5;
00236 }
00237
00238 theFEs[numFeEle++] = fePtr;
00239
00240 theModel->addFE_Element(fePtr);
00241 }
00242
00243 return count3;
00244 }
00245
00246
00247 void
00248 PenaltyConstraintHandler::clearAll(void)
00249 {
00250
00251 for (int i=0; i<numFE; i++)
00252 if (theFEs[i] != 0)
00253 delete theFEs[i];
00254
00255 for (int j=0; j<numDOF; j++)
00256 if (theDOFs[j] != 0)
00257 delete theDOFs[j];
00258
00259
00260 if (theFEs != 0) delete [] theFEs;
00261 if (theDOFs != 0) delete [] theDOFs;
00262
00263
00264 numDOF = 0;
00265 numFE = 0;
00266 theFEs = 0;
00267 theDOFs = 0;
00268
00269
00270 Domain *theDomain = this->getDomainPtr();
00271 if (theDomain == 0)
00272 return;
00273
00274 NodeIter &theNod = theDomain->getNodes();
00275 Node *nodPtr;
00276 while ((nodPtr = theNod()) != 0)
00277 nodPtr->setDOF_GroupPtr(0);
00278 }
00279
00280 int
00281 PenaltyConstraintHandler::sendSelf(int cTag, Channel &theChannel)
00282 {
00283 Vector data(2);
00284 int result = 0;
00285 data(0) = alphaSP;
00286 data(1) = alphaMP;
00287 result = theChannel.sendVector(this->getDbTag(), cTag, data);
00288 if (result != 0)
00289 cerr << "PenaltyConstraintHandler::sendSelf() - error sending Vector\n";
00290 return result;
00291 }
00292
00293 int
00294 PenaltyConstraintHandler::recvSelf(int cTag,
00295 Channel &theChannel,
00296 FEM_ObjectBroker &theBroker)
00297 {
00298 Vector data(2);
00299 int result = 0;
00300 result = theChannel.sendVector(this->getDbTag(), cTag, data);
00301 alphaSP = data(0);
00302 alphaMP = data(1);
00303 if (result != 0)
00304 cerr << "PenaltyConstraintHandler::recvSelf() - error receiving Vector\n";
00305 return result;
00306 }