PageRenderTime 58ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/opensees-websocket/SRC/element/joint/MP_Joint2D.cpp

https://code.google.com/
C++ | 503 lines | 342 code | 97 blank | 64 comment | 110 complexity | 9a06c47d7a1103cdb657d217aa93a4a5 MD5 | raw file
  1. /* ****************************************************************** **
  2. ** OpenSees - Open System for Earthquake Engineering Simulation **
  3. ** Pacific Earthquake Engineering Research Center **
  4. ** **
  5. ** **
  6. ** (C) Copyright 1999, The Regents of the University of California **
  7. ** All Rights Reserved. **
  8. ** **
  9. ** Commercial use of this program without express permission of the **
  10. ** University of California, Berkeley, is strictly prohibited. See **
  11. ** file 'COPYRIGHT' in main directory for information on usage and **
  12. ** redistribution, and for a DISCLAIMER OF ALL WARRANTIES. **
  13. ** **
  14. ** Developed by: **
  15. ** Frank McKenna (fmckenna@ce.berkeley.edu) **
  16. ** Gregory L. Fenves (fenves@ce.berkeley.edu) **
  17. ** Filip C. Filippou (filippou@ce.berkeley.edu) **
  18. ** **
  19. ** ****************************************************************** */
  20. // $Revision: 1.7 $
  21. // $Date: 2010-04-23 22:53:56 $
  22. // $Source: /usr/local/cvs/OpenSees/SRC/element/joint/MP_Joint2D.cpp,v $
  23. // Written: Arash Altoontash, Gregory Deierlein
  24. // Created: 08/01
  25. // Revision: Arash
  26. // Purpose: This file contains the implementation of class MP_TimeVary.
  27. #include <MP_Joint2D.h>
  28. #include <stdlib.h>
  29. #include <math.h>
  30. #include <Matrix.h>
  31. #include <ID.h>
  32. #include <Channel.h>
  33. #include <FEM_ObjectBroker.h>
  34. // main degree of freedom for rotation
  35. // constructor for FEM_ObjectBroker
  36. MP_Joint2D::MP_Joint2D()
  37. :MP_Constraint(CNSTRNT_TAG_MP_Joint2D ),thisDomain(0),
  38. nodeRetained(0),nodeConstrained(0), MainDOF(0), AuxDOF(0), FixedEnd(0),
  39. constraint(0), constrDOF(0),retainDOF(0),dbTag1(0), dbTag2(0), dbTag3(0),
  40. RetainedNode(0), ConstrainedNode(0), LargeDisplacement(0), Length0(0.0)
  41. {
  42. }
  43. // general constructor for ModelBuilder
  44. MP_Joint2D::MP_Joint2D(Domain *theDomain, int nodeRetain, int nodeConstr,
  45. int Maindof, int fixedend, int LrgDsp )
  46. :MP_Constraint(CNSTRNT_TAG_MP_Joint2D ), thisDomain(theDomain),
  47. nodeRetained(nodeRetain), nodeConstrained(nodeConstr), MainDOF(Maindof), AuxDOF(0),
  48. FixedEnd(fixedend), constraint(0), constrDOF(0), retainDOF(0),
  49. dbTag1(0), dbTag2(0), dbTag3(0), RetainedNode(0), ConstrainedNode(0),
  50. LargeDisplacement( LrgDsp ), Length0(0.0)
  51. {
  52. if( thisDomain == NULL ) {
  53. opserr << "WARNING MP_Joint2D(): Specified domain does not exist";
  54. opserr << "Domain = 0\n";
  55. return;
  56. }
  57. // get node pointers of constrainted and retained nodes
  58. ConstrainedNode = theDomain->getNode(nodeConstrained);
  59. if (ConstrainedNode == NULL)
  60. {
  61. opserr << "MP_Joint2D::MP_Joint2D: nodeConstrained: ";
  62. opserr << nodeConstrained << "does not exist in model\n";
  63. exit(0);
  64. }
  65. RetainedNode = theDomain->getNode(nodeRetained);
  66. if (RetainedNode == NULL)
  67. {
  68. opserr << "MP_Joint2D::MP_Joint2D: nodeRetained: ";
  69. opserr << nodeRetained << "does not exist in model\n";
  70. exit(0);
  71. }
  72. // check for proper degrees of freedom
  73. int RnumDOF = RetainedNode->getNumberDOF();
  74. int CnumDOF = ConstrainedNode->getNumberDOF();
  75. if (RnumDOF != 4 || CnumDOF != 3 ){
  76. opserr << "MP_Joint2D::MP_Joint2D - mismatch in numDOF\n DOF not supported by this type of constraint";
  77. return;
  78. }
  79. // check the main degree of freedom. Assign auxilary DOF
  80. if ( MainDOF!= 2 && MainDOF!=3 ) {
  81. opserr << "MP_Joint2D::MP_Joint2D - Wrong main degree of freedom" ;
  82. return;
  83. }
  84. if ( MainDOF == 2 ) AuxDOF = 3;
  85. if ( MainDOF == 3 ) AuxDOF = 2;
  86. // check the fixed end flag
  87. if ( FixedEnd!= 0 && FixedEnd!=1 ) {
  88. opserr << "MP_Joint2D::MP_Joint2D - Wrong fixed end flag";
  89. return;
  90. }
  91. // check for proper dimensions of coordinate space
  92. const Vector &crdR = RetainedNode->getCrds();
  93. int dimR = crdR.Size();
  94. const Vector &crdC = ConstrainedNode->getCrds();
  95. int dimC = crdC.Size();
  96. if (dimR != 2 || dimC != 2 ){
  97. opserr << "MP_Joint2D::MP_Joint2D - mismatch in dimnesion\n dimension not supported by this type of constraint";
  98. return;
  99. }
  100. // calculate the initial length of the rigid link
  101. double deltaX = crdC(0) - crdR(0);
  102. double deltaY = crdC(1) - crdR(1);
  103. Length0 = sqrt( deltaX*deltaX + deltaY*deltaY );
  104. if ( Length0 <= 1.0e-12 ) {
  105. opserr << "MP_Joint2D::MP_Joint2D - The constraint length is zero\n";
  106. }
  107. // allocate and set up the constranted and retained id's
  108. // allocate and set up the constraint matrix
  109. if ( FixedEnd == 0 )
  110. {
  111. // the end is released
  112. constrDOF = new ID(CnumDOF-1);
  113. retainDOF = new ID(RnumDOF-1);
  114. (*constrDOF)(0) = 0;
  115. (*constrDOF)(1) = 1;
  116. (*retainDOF)(0) = 0;
  117. (*retainDOF)(1) = 1;
  118. (*retainDOF)(2) = MainDOF;
  119. constraint = new Matrix( CnumDOF-1 , RnumDOF-1 );
  120. (*constraint) (0,0) = 1.0 ;
  121. (*constraint) (0,2) = -deltaY ;
  122. (*constraint) (1,1) = 1.0 ;
  123. (*constraint) (1,2) = deltaX ;
  124. } else
  125. {
  126. // the end is fixed
  127. constrDOF = new ID(CnumDOF);
  128. retainDOF = new ID(RnumDOF);
  129. (*constrDOF)(0) = 0;
  130. (*constrDOF)(1) = 1;
  131. (*constrDOF)(2) = 2;
  132. (*retainDOF)(0) = 0;
  133. (*retainDOF)(1) = 1;
  134. (*retainDOF)(2) = 2;
  135. (*retainDOF)(3) = 3;
  136. constraint = new Matrix( CnumDOF , RnumDOF );
  137. (*constraint) (0,0) = 1.0 ;
  138. (*constraint) (0,MainDOF) = -deltaY ;
  139. (*constraint) (1,1) = 1.0 ;
  140. (*constraint) (1,MainDOF) = deltaX ;
  141. (*constraint) (2,AuxDOF) = 1.0 ;
  142. }
  143. if (constrDOF == NULL || retainDOF == NULL ) {
  144. opserr << "MP_Joint2D::MP_Joint2D - ran out of memory \ncan not generate ID for nodes\n";
  145. exit(-1);
  146. }
  147. if (constraint == NULL ) {
  148. opserr << "MP_Joint2D::MP_Joint2D - ran out of memory \ncan not generate the constraint matrix";
  149. exit(-1);
  150. }
  151. }
  152. MP_Joint2D::~MP_Joint2D()
  153. {
  154. // invoke the destructor on the matrix and the two ID objects
  155. if (constraint != NULL)
  156. delete constraint;
  157. if (constrDOF != NULL)
  158. delete constrDOF;
  159. if (retainDOF != NULL)
  160. delete retainDOF;
  161. }
  162. int
  163. MP_Joint2D::getNodeRetained(void) const
  164. {
  165. // return id of retained node
  166. return nodeRetained;
  167. }
  168. int
  169. MP_Joint2D::getNodeConstrained(void) const
  170. {
  171. // return id of constrained node
  172. return nodeConstrained;
  173. }
  174. const ID &
  175. MP_Joint2D::getConstrainedDOFs(void) const
  176. {
  177. if (constrDOF == NULL) {
  178. opserr << "MP_Joint2D::getConstrainedDOF - no ID was set, ";
  179. opserr << "was recvSelf() ever called? or subclass incorrect?\n";
  180. exit(-1);
  181. }
  182. // return the ID corresponding to constrained DOF of Ccr
  183. return (*constrDOF);
  184. }
  185. const ID &
  186. MP_Joint2D::getRetainedDOFs(void) const
  187. {
  188. if (retainDOF == NULL) {
  189. opserr << "MP_Joint2D::getRetainedDOFs - no ID was set\n ";
  190. opserr << "was recvSelf() ever called? or subclass incorrect?\n";
  191. exit(-1);
  192. }
  193. // return the ID corresponding to retained DOF of Ccr
  194. return (*retainDOF);
  195. }
  196. int
  197. MP_Joint2D::applyConstraint(double timeStamp)
  198. {
  199. if ( LargeDisplacement != 0 )
  200. {
  201. // calculate the constraint at this moment
  202. // get the coordinates of the two nodes - check dimensions are the same FOR THE MOMENT
  203. const Vector &crdR = RetainedNode->getCrds();
  204. const Vector &crdC = ConstrainedNode->getCrds();
  205. // get commited displacements of nodes to get updated coordinates
  206. const Vector &dispR = RetainedNode->getDisp();
  207. const Vector &dispC = ConstrainedNode->getDisp();
  208. double deltaX = dispC(0) + crdC(0) - dispR(0) - crdR(0);
  209. double deltaY = dispC(1) + crdC(1) - dispR(1) - crdR(1);
  210. constraint->Zero();
  211. if ( FixedEnd == 0 )
  212. {
  213. // the end is released
  214. (*constraint) (0,0) = 1.0 ;
  215. (*constraint) (0,2) = -deltaY ;
  216. (*constraint) (1,1) = 1.0 ;
  217. (*constraint) (1,2) = deltaX ;
  218. } else
  219. {
  220. // the end is fixed
  221. (*constraint) (0,0) = 1.0 ;
  222. (*constraint) (0,MainDOF) = -deltaY ;
  223. (*constraint) (1,1) = 1.0 ;
  224. (*constraint) (1,MainDOF) = deltaX ;
  225. (*constraint) (2,AuxDOF) = 1.0 ;
  226. }
  227. }
  228. return 0;
  229. }
  230. bool
  231. MP_Joint2D::isTimeVarying(void) const
  232. {
  233. if ( LargeDisplacement != 0 ) return true;
  234. return false;
  235. }
  236. int MP_Joint2D::sendSelf(int commitTag, Channel &theChannel)
  237. {
  238. Vector data(15);
  239. int dataTag = this->getDbTag();
  240. data(0) = this->getTag();
  241. data(1) = nodeRetained;
  242. data(2) = nodeConstrained;
  243. data(3) = MainDOF;
  244. data(4) = AuxDOF;
  245. data(5) = FixedEnd;
  246. if (constrDOF == 0) data(6) = 0; else data(6) = constrDOF->Size();
  247. if (retainDOF == 0) data(7) = 0; else data(7) = retainDOF->Size();
  248. if (constraint == 0) data(8) = 0; else data(8) = constraint->noRows();
  249. if (constraint == 0) data(9) = 0; else data(9) = constraint->noCols();
  250. // need two database tags for ID objects
  251. if (constrDOF != 0 && dbTag1 == 0) dbTag1 = theChannel.getDbTag();
  252. if (retainDOF != 0 && dbTag2 == 0) dbTag2 = theChannel.getDbTag();
  253. if (constraint != 0 && dbTag3 == 0) dbTag3 = theChannel.getDbTag();
  254. data(10) = dbTag1;
  255. data(11) = dbTag2;
  256. data(12) = dbTag3;
  257. data(13) = LargeDisplacement;
  258. data(14) = Length0;
  259. // now send the data vector
  260. int result = theChannel.sendVector(dataTag, commitTag, data);
  261. if (result < 0) {
  262. opserr << "WARNING MP_Joint2D::sendSelf - error sending ID data\n";
  263. return result;
  264. }
  265. // send constrDOF
  266. if (constrDOF != 0 && constrDOF->Size() != 0) {
  267. int result = theChannel.sendID(dbTag1, commitTag, *constrDOF);
  268. if (result < 0) {
  269. opserr << "WARNING MP_Joint2D::sendSelf ";
  270. opserr << "- error sending constrained DOF data\n";
  271. return result;
  272. }
  273. }
  274. // send retainDOF
  275. if (retainDOF != 0 && retainDOF->Size() != 0) {
  276. int result = theChannel.sendID(dbTag2, commitTag, *retainDOF);
  277. if (result < 0) {
  278. opserr << "WARNING MP_Joint2D::sendSelf ";
  279. opserr << "- error sending retained DOF data\n";
  280. return result;
  281. }
  282. }
  283. // send constraint matrix
  284. if (constraint != 0 && constraint->noRows() != 0) {
  285. int result = theChannel.sendMatrix(dbTag3, commitTag, *constraint);
  286. if (result < 0) {
  287. opserr << "WARNING MP_Joint2D::sendSelf ";
  288. opserr << "- error sending constraint Matrix data\n";
  289. return result;
  290. }
  291. }
  292. return 0;
  293. }
  294. int MP_Joint2D::recvSelf(int commitTag, Channel &theChannel,
  295. FEM_ObjectBroker &theBroker)
  296. {
  297. int dataTag = this->getDbTag();
  298. Vector data(15);
  299. int result = theChannel.recvVector(dataTag, commitTag, data);
  300. if (result < 0) {
  301. opserr << "WARNING MP_Joint2D::recvSelf - error receiving ID data\n";
  302. return result;
  303. }
  304. this->setTag( (int) data(0));
  305. nodeRetained = (int) data(1);
  306. nodeConstrained = (int) data(2);
  307. MainDOF = (int) data(3);
  308. AuxDOF = (int) data(4);
  309. FixedEnd = (int) data(5);
  310. int constrDOFsize = (int) data(6);
  311. int retainDOFsize = (int) data(7);
  312. int numRows = (int) data(8);
  313. int numCols = (int) data(9);
  314. dbTag1 = (int) data(10);
  315. dbTag2 = (int) data(11);
  316. dbTag3 = (int) data(12);
  317. LargeDisplacement = (int) data(13);
  318. Length0 = data(14);
  319. // receive constrDOF ID
  320. if (constrDOFsize != 0) {
  321. constrDOF = new ID(constrDOFsize);
  322. int result = theChannel.recvID(dbTag1, commitTag, *constrDOF);
  323. if (result < 0) {
  324. opserr << "WARNING MP_Joint2D::recvSelf ";
  325. opserr << "- error receiving constrained data\n";
  326. return result;
  327. }
  328. }
  329. // receive retainDOF ID
  330. if (retainDOFsize != 0) {
  331. retainDOF = new ID(retainDOFsize);
  332. int result = theChannel.recvID(dbTag2, commitTag, *retainDOF);
  333. if (result < 0) {
  334. opserr << "WARNING MP_Joint2D::recvSelf ";
  335. opserr << "- error receiving retained data\n";
  336. return result;
  337. }
  338. }
  339. // receive the constraint matrix
  340. if (numRows != 0 && numCols != 0) {
  341. constraint = new Matrix(numRows,numCols);
  342. int result = theChannel.recvMatrix(dbTag3, commitTag, *constraint);
  343. if (result < 0) {
  344. opserr << "WARNING MP_Joint2D::recvSelf ";
  345. opserr << "- error receiving Matrix data\n";
  346. return result;
  347. }
  348. }
  349. return 0;
  350. }
  351. const Matrix &MP_Joint2D::getConstraint(void)
  352. {
  353. if (constraint == 0) {
  354. opserr << "MP_Joint2D::getConstraint - no Matrix was set\n";
  355. exit(-1);
  356. }
  357. // Length correction
  358. // to correct the trial displacement
  359. if ( LargeDisplacement == 2 )
  360. {
  361. // get the coordinates of the two nodes - check dimensions are the same FOR THE MOMENT
  362. const Vector &crdR = RetainedNode->getCrds();
  363. const Vector &crdC = ConstrainedNode->getCrds();
  364. // get commited displacements of nodes to get updated coordinates
  365. const Vector &dispR = RetainedNode->getTrialDisp();
  366. const Vector &dispC = ConstrainedNode->getTrialDisp();
  367. double deltaX = dispC(0) + crdC(0) - dispR(0) - crdR(0);
  368. double deltaY = dispC(1) + crdC(1) - dispR(1) - crdR(1);
  369. Vector Direction(2);
  370. Direction(0) = deltaX;
  371. Direction(1) = deltaY;
  372. double NewLength = Direction.Norm();
  373. if ( NewLength < 1e-12 ) opserr << "MP_Joint2D::applyConstraint : length of rigid link is too small or zero";
  374. Direction = Direction * (Length0/NewLength); // correct the length
  375. // find new displacements of the constrainted node
  376. Vector NewLocation(3);
  377. NewLocation(0) = Direction(0) + dispR(0) + crdR(0) - crdC(0);
  378. NewLocation(1) = Direction(1) + dispR(1) + crdR(1) - crdC(1);
  379. NewLocation(2) = dispC(2);
  380. int dummy = ConstrainedNode->setTrialDisp( NewLocation );
  381. }
  382. // end of length correction procedure
  383. // return the constraint matrix Ccr
  384. return (*constraint);
  385. }
  386. void MP_Joint2D::Print(OPS_Stream &s, int flag )
  387. {
  388. s << "MP_Joint2D: " << this->getTag() << "\n";
  389. s << "\tConstrained Node: " << nodeConstrained;
  390. s << " Retained Node: " << nodeRetained ;
  391. s << " Fixed end: " << FixedEnd << " Large Disp: " << LargeDisplacement;
  392. if (constrDOF != 0)
  393. s << " constrained dof: " << *constrDOF;
  394. if (retainDOF != 0)
  395. s << " retained dof: " << *retainDOF;
  396. if (constraint != 0)
  397. s << " constraint matrix: " << *constraint << "\n";
  398. }
  399. void
  400. MP_Joint2D::setDomain(Domain *theDomain)
  401. {
  402. this->DomainComponent::setDomain(theDomain);
  403. thisDomain = theDomain;
  404. RetainedNode = thisDomain->getNode(nodeRetained);
  405. ConstrainedNode = thisDomain->getNode(nodeConstrained);
  406. }