method: setDomain() to set a link to the enclosing Domain, ensure nodes exist in Domain and set pointers to these nodes, also determines the length and transformation Matrix.
| 206 | // and set pointers to these nodes, also determines the length and |
| 207 | // transformation Matrix. |
| 208 | void |
| 209 | Truss2D::setDomain(Domain *theDomain) |
| 210 | { |
| 211 | // check Domain is not null - invoked when object removed from a domain |
| 212 | if (theDomain == 0) { |
| 213 | return; |
| 214 | } |
| 215 | |
| 216 | // first ensure nodes exist in Domain and set the node pointers |
| 217 | Node *end1Ptr, *end2Ptr; |
| 218 | int Nd1 = externalNodes(0); |
| 219 | int Nd2 = externalNodes(1); |
| 220 | end1Ptr = theDomain->getNode(Nd1); |
| 221 | end2Ptr = theDomain->getNode(Nd2); |
| 222 | if (end1Ptr == 0) { |
| 223 | opserr << "WARNING Truss2D::setDomain() - at truss " << this->getTag() << " node " << |
| 224 | Nd1 << " does not exist in domain\n"; |
| 225 | |
| 226 | return; // don't go any further - otherwise segemntation fault |
| 227 | } |
| 228 | if (end2Ptr == 0) { |
| 229 | opserr << "WARNING Truss2D::setDomain() - at truss " << this->getTag() << " node " << |
| 230 | Nd2 << " does not exist in domain\n"; |
| 231 | |
| 232 | return; // don't go any further - otherwise segemntation fault |
| 233 | } |
| 234 | theNodes[0] = end1Ptr; |
| 235 | theNodes[1] = end2Ptr; |
| 236 | // call the DomainComponent class method THIS IS VERY IMPORTANT |
| 237 | this->DomainComponent::setDomain(theDomain); |
| 238 | |
| 239 | // ensure connected nodes have correct number of dof's |
| 240 | int dofNd1 = end1Ptr->getNumberDOF(); |
| 241 | int dofNd2 = end2Ptr->getNumberDOF(); |
| 242 | if ((dofNd1 != 2) || (dofNd2 != 2)) { |
| 243 | opserr << "Truss2D::setDomain(): 2 dof required at nodes\n"; |
| 244 | return; |
| 245 | } |
| 246 | |
| 247 | // now determine the length & transformation matrix |
| 248 | const Vector &end1Crd = end1Ptr->getCrds(); |
| 249 | const Vector &end2Crd = end2Ptr->getCrds(); |
| 250 | |
| 251 | double dx = end2Crd(0)-end1Crd(0); |
| 252 | double dy = end2Crd(1)-end1Crd(1); |
| 253 | |
| 254 | L = sqrt(dx*dx + dy*dy); |
| 255 | |
| 256 | if (L == 0.0) { |
| 257 | opserr << "WARNING Truss2D::setDomain() - Truss2D " << this->getTag() << |
| 258 | " has zero length\n"; |
| 259 | return; // don't go any further - otherwise divide by 0 error |
| 260 | } |
| 261 | |
| 262 | double cs = dx/L; |
| 263 | double sn = dy/L; |
| 264 | |
| 265 | trans(0,0) = -cs; |
nothing calls this directly
no test coverage detected