![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsFEMMeshHexahedra.cpp 00003 ******************************************************************************/ 00007 /****************************************************************************** 00008 SUKITTI PUNAK (02/11/2010) 00009 UPDATE (09/03/2010) 00010 ******************************************************************************/ 00011 #include "TAPsFEMMeshHexahedra.hpp" 00012 // Using Inclusion Model (i.e. definitions are included in declarations) 00013 // (this name.cpp is included in name.hpp) 00014 // Each friend is defined directly inside its declaration. 00015 00016 BEGIN_NAMESPACE_TAPs__FEM 00017 //============================================================================= 00018 // Constructors 00019 //----------------------------------------------------------------------------- 00020 template <typename T> 00021 MeshHexahedra<T>::MeshHexahedra () 00022 { 00023 //std::cout << "START: Default Ctor of MeshHexahedra<T> ------------------\n"; 00024 Init(); 00025 //std::cout << "END: Default Ctor of MeshHexahedra<T> --------------------\n"; 00026 } 00027 //----------------------------------------------------------------------------- 00028 //template <typename T> 00029 //MeshHexahedra<T>::MeshHexahedra ( MeshHexahedra<T> const &orig ) 00030 //{} 00031 //----------------------------------------------------------------------------- 00032 template <typename T> 00033 MeshHexahedra<T>::~MeshHexahedra () 00034 {} 00035 //----------------------------------------------------------------------------- 00036 template <typename T> 00037 std::string MeshHexahedra<T>::StrInfo () const 00038 { 00039 std::stringstream ss; 00040 std::vector< Hexahedron<T> >::const_iterator it = m_vElements.begin(); 00041 ss << "FEM::Hexahedra Mesh<" << typeid(T).name() << ">:\n"; 00042 while ( it != m_vElements.end() ) { 00043 ss << *it; 00044 ++it; 00045 } 00046 return ss.str(); 00047 } 00048 //----------------------------------------------------------------------------- 00049 00050 //----------------------------------------------------------------------------- 00051 template <typename T> 00052 void MeshHexahedra<T>::Init () 00053 { 00054 FEM::Hexahedron<T>::UpdateShapeFnsPartialDerivatives_1PtGuassRule(); 00055 FEM::Hexahedron<T>::UpdateShapeFnsPartialDerivatives_2PtGuassRule(); 00056 00057 m_vDeformedMeshNodes.push_back( Vector3<T>(0,0,0) ); 00058 m_vDeformedMeshNodes.push_back( Vector3<T>(0,0,0) ); 00059 m_vDeformedMeshNodes.push_back( Vector3<T>(0,0,0) ); 00060 m_vDeformedMeshNodes.push_back( Vector3<T>(0,0,0) ); 00061 m_vDeformedMeshNodes.push_back( Vector3<T>(0,0,0) ); 00062 m_vDeformedMeshNodes.push_back( Vector3<T>(0,0,0) ); 00063 m_vDeformedMeshNodes.push_back( Vector3<T>(0,0,0) ); 00064 m_vDeformedMeshNodes.push_back( Vector3<T>(0,0,0) ); 00065 00066 m_vUndeformedMeshNodes.push_back( Vector3<T>(0,0,0) ); 00067 m_vUndeformedMeshNodes.push_back( Vector3<T>(1,0,0) ); 00068 m_vUndeformedMeshNodes.push_back( Vector3<T>(1,1,0) ); 00069 m_vUndeformedMeshNodes.push_back( Vector3<T>(0,1,0) ); 00070 m_vUndeformedMeshNodes.push_back( Vector3<T>(0,0,1) ); 00071 m_vUndeformedMeshNodes.push_back( Vector3<T>(1,0,1) ); 00072 m_vUndeformedMeshNodes.push_back( Vector3<T>(1,1,1) ); 00073 m_vUndeformedMeshNodes.push_back( Vector3<T>(0,1,1) ); 00074 00075 m_vElements.push_back( Hexahedron<T>( 00076 &(RetListOfDeformedMeshNodes()), 00077 &(RetListOfUndeformedMeshNodes()), 00078 1.0, // Young's modulus 00079 0.01, // Poisson's ratio 00080 0, 1, 2, 3, 4, 5, 6, 7 ) 00081 ); 00082 } 00083 //----------------------------------------------------------------------------- 00084 00085 //============================================================================= 00086 // Assignment Operator 00087 //----------------------------------------------------------------------------- 00088 //template <typename T> 00089 //MeshHexahedra<T> & MeshHexahedra<T>::operator= ( MeshHexahedra<T> const &orig ) 00090 //{} 00091 //----------------------------------------------------------------------------- 00092 //============================================================================= 00093 00094 00095 //============================================================================= 00096 // Operations 00097 //----------------------------------------------------------------------------- 00098 //template <typename T> 00099 //void MeshHexahedra<T>::ResetToDeformedState () 00100 //{ 00101 // std::vector< Hexahedron<T> >::iterator it = m_vElements.begin(); 00102 // while ( it != m_vElements.end() ) { 00103 // it->ResetToDeformedState(); 00104 // ++it; 00105 // } 00106 //} 00107 //----------------------------------------------------------------------------- 00108 template <typename T> 00109 void MeshHexahedra<T>::ResetToUndeformedState () 00110 { 00111 std::vector< Hexahedron<T> >::iterator it = m_vElements.begin(); 00112 while ( it != m_vElements.end() ) { 00113 it->ResetToUndeformedState(); 00114 ++it; 00115 } 00116 00117 #ifdef TAPs_SIM_DYNAMIC_SYSTEM 00118 ResetCurrentVelocities(); 00119 #endif//TAPs_SIM_DYNAMIC_SYSTEM 00120 } 00121 //----------------------------------------------------------------------------- 00122 template <typename T> 00123 void MeshHexahedra<T>::AssembleStiffnessMatrix () 00124 { 00125 #ifdef TAPs_USE_SYMMETRIC_MATRIX 00126 Mstiff.SetDirectAccessors(); 00127 std::vector< Hexahedron<T> >::iterator it = m_vElements.begin(); 00128 while( it != m_vElements.end() ) { 00129 for ( int n = 0; n < 8; ++n ) { 00130 for ( int m = 0; m < 8; ++m ) { 00131 if ( it->ids[n] <= it->ids[m] ) { 00132 Mstiff.DirectAccess( it->ids[n] )->UpdateAdd( it->ids[m], it->GetStiffnessMatrix( n, m ) ); 00133 } 00134 } 00135 } 00136 ++it; 00137 } 00138 #else //TAPs_USE_SYMMETRIC_MATRIX 00139 Mstiff.SetDirectAccessors(); 00140 std::vector< Hexahedron<T> >::iterator it = m_vElements.begin(); 00141 while( it != m_vElements.end() ) { 00142 for ( int n = 0; n < 8; ++n ) { 00143 for ( int m = 0; m < 8; ++m ) { 00144 Mstiff.DirectAccess( it->ids[n] )->UpdateAdd( it->ids[m], it->GetStiffnessMatrix( n, m ) ); 00145 } 00146 } 00147 ++it; 00148 } 00149 #endif//TAPs_USE_SYMMETRIC_MATRIX 00150 //*/ 00151 00152 // DEBUG 00153 //std::cout << "HexFEM Mstiff: " << Mstiff << "\n"; 00154 } 00155 //----------------------------------------------------------------------------- 00156 template <typename T> 00157 void MeshHexahedra<T>::UpdateStrainDisplacementMatrix () 00158 { 00159 std::vector< Hexahedron<T> >::iterator it = m_vElements.begin(); 00160 while ( it != m_vElements.end() ) { 00161 it->UpdateStrainDisplacementMatrixElements(); 00162 ++it; 00163 } 00164 } 00165 //----------------------------------------------------------------------------- 00166 //============================================================================= 00167 00168 00169 00170 00171 //============================================================================= 00172 // Get/Set Fns 00173 //----------------------------------------------------------------------------- 00174 template <typename T> 00175 unsigned int MeshHexahedra<T>::GetNumOfElements () const 00176 { 00177 return m_vElements.size(); 00178 } 00179 00180 template <typename T> 00181 Hexahedron<T> const & MeshHexahedra<T>::RefToElement ( unsigned int i ) const 00182 { 00183 assert( i < GetNumOfElements() ); 00184 return m_vElements[i]; 00185 } 00186 00187 template <typename T> 00188 Hexahedron<T> & MeshHexahedra<T>::RefToElement ( unsigned int i ) 00189 { 00190 assert( i < GetNumOfElements() ); 00191 return m_vElements[i]; 00192 } 00193 //----------------------------------------------------------------------------- 00194 //============================================================================= 00195 00196 00197 00198 00199 //============================================================================= 00200 // Simulation 00201 //----------------------------------------------------------------------------- 00202 template <typename T> 00203 void MeshHexahedra<T>::AdvanceSimulationStatic () 00204 { 00205 Mesh<T>::AdvanceSimulationStatic(); 00206 } 00207 00208 #ifdef TAPs_SIM_DYNAMIC_SYSTEM 00209 template <typename T> 00210 void MeshHexahedra<T>::AdvanceSimulationDynamic () 00211 { 00212 Mesh<T>::AdvanceSimulationDynamic(); 00213 } 00214 #endif//TAPs_SIM_DYNAMIC_SYSTEM 00215 00216 //------------------------------------------------------------------- 00217 template <typename T> 00218 void MeshHexahedra<T>::AllocateDataForSimulation ( T mass ) 00219 { 00220 Mesh<T>::AllocateDataForSimulation( mass ); 00221 } 00222 00223 //----------------------------------------------------------------------------- 00224 //============================================================================= 00225 00226 00227 //============================================================================= 00228 // Checking 00229 //----------------------------------------------------------------------------- 00230 template <typename T> 00231 std::string MeshHexahedra<T>::CheckVolumeOfEachElement () 00232 { 00233 unsigned int count = 0; 00234 std::stringstream ss; 00235 std::vector< Hexahedron<T> >::iterator it = m_vElements.begin(); 00236 while ( it != m_vElements.end() ) { 00237 ss //<< "Element# " << count++ << " Deformed - Undeformed Volume: " 00238 << "#" << count++ << ": " << it->CalDeformedVolume() << " - " << it->CalUndeformedVolume() << "; "; 00239 ++it; 00240 } 00241 return ss.str(); 00242 } 00243 //----------------------------------------------------------------------------- 00244 //============================================================================= 00245 00246 00247 00248 //============================================================================= 00249 // For interactions 00250 #ifdef TAPs_ADD_INTERACTIONS 00251 //----------------------------------------------------------------------------- 00252 template <typename T> 00253 void MeshHexahedra<T>::ApplyPointLoad ( PointForce<T> const * const ptrPtForce ) 00254 { 00255 static T weights[8]; 00256 Hexahedron<T>::InterpolateShapeFunctions( ptrPtForce->RefToPosition()[0], ptrPtForce->RefToPosition()[1], ptrPtForce->RefToPosition()[2], weights ); 00257 00258 // Add distributed node forces 00259 if ( !IsFixedNode( m_vElements[ ptrPtForce->GetID() ].GetGlobalNodeNumberFromLocalNode( 0 ) ) ) { 00260 m_Forces[ m_vElements[ ptrPtForce->GetID() ].GetGlobalNodeNumberFromLocalNode( 0 ) ] += weights[0] * ptrPtForce->RefToForce(); 00261 } 00262 if ( !IsFixedNode( m_vElements[ ptrPtForce->GetID() ].GetGlobalNodeNumberFromLocalNode( 1 ) ) ) { 00263 m_Forces[ m_vElements[ ptrPtForce->GetID() ].GetGlobalNodeNumberFromLocalNode( 1 ) ] += weights[1] * ptrPtForce->RefToForce(); 00264 } 00265 if ( !IsFixedNode( m_vElements[ ptrPtForce->GetID() ].GetGlobalNodeNumberFromLocalNode( 2 ) ) ) { 00266 m_Forces[ m_vElements[ ptrPtForce->GetID() ].GetGlobalNodeNumberFromLocalNode( 2 ) ] += weights[2] * ptrPtForce->RefToForce(); 00267 } 00268 if ( !IsFixedNode( m_vElements[ ptrPtForce->GetID() ].GetGlobalNodeNumberFromLocalNode( 3 ) ) ) { 00269 m_Forces[ m_vElements[ ptrPtForce->GetID() ].GetGlobalNodeNumberFromLocalNode( 3 ) ] += weights[3] * ptrPtForce->RefToForce(); 00270 } 00271 if ( !IsFixedNode( m_vElements[ ptrPtForce->GetID() ].GetGlobalNodeNumberFromLocalNode( 4 ) ) ) { 00272 m_Forces[ m_vElements[ ptrPtForce->GetID() ].GetGlobalNodeNumberFromLocalNode( 4 ) ] += weights[4] * ptrPtForce->RefToForce(); 00273 } 00274 if ( !IsFixedNode( m_vElements[ ptrPtForce->GetID() ].GetGlobalNodeNumberFromLocalNode( 5 ) ) ) { 00275 m_Forces[ m_vElements[ ptrPtForce->GetID() ].GetGlobalNodeNumberFromLocalNode( 5 ) ] += weights[5] * ptrPtForce->RefToForce(); 00276 } 00277 if ( !IsFixedNode( m_vElements[ ptrPtForce->GetID() ].GetGlobalNodeNumberFromLocalNode( 6 ) ) ) { 00278 m_Forces[ m_vElements[ ptrPtForce->GetID() ].GetGlobalNodeNumberFromLocalNode( 6 ) ] += weights[6] * ptrPtForce->RefToForce(); 00279 } 00280 if ( !IsFixedNode( m_vElements[ ptrPtForce->GetID() ].GetGlobalNodeNumberFromLocalNode( 7 ) ) ) { 00281 m_Forces[ m_vElements[ ptrPtForce->GetID() ].GetGlobalNodeNumberFromLocalNode( 7 ) ] += weights[7] * ptrPtForce->RefToForce(); 00282 } 00283 00284 /* 00285 // DEBUG 00286 std::cout << "weights: "; 00287 for ( int i = 0; i < 8; ++i ) { 00288 std::cout << "\t" << weights[i]; 00289 } 00290 std::cout << "\n"; 00291 //*/ 00292 } 00293 //----------------------------------------------------------------------------- 00294 #endif//TAPs_ADD_INTERACTIONS 00295 //============================================================================= 00296 00297 00298 00299 00300 //============================================================================= 00301 // OpenGL 00302 #if defined(__gl_h_) || defined(__GL_H__) 00303 //----------------------------------------------------------------------------- 00304 template <typename T> 00305 void MeshHexahedra<T>::Draw () 00306 { 00307 if ( m_pTrx ) { 00308 glPushMatrix(); 00309 m_pTrx->TransformByOpenGLForDrawing(); 00310 } 00311 00312 glPushAttrib( GL_ALL_ATTRIB_BITS ); 00313 glDisable( GL_LIGHTING ); 00314 std::vector< Hexahedron<T> >::iterator it = m_vElements.begin(); 00315 while ( it != m_vElements.end() ) { 00316 it->Draw(); 00317 ++it; 00318 } 00319 glPopAttrib(); 00320 00321 if ( m_pTrx ) { 00322 glPopMatrix(); 00323 } 00324 } 00325 00326 //----------------------------------------------------------------------------- 00327 template <typename T> 00328 void MeshHexahedra<T>::DrawUndeformedMesh () 00329 { 00330 if ( m_pTrx ) { 00331 glPushMatrix(); 00332 m_pTrx->TransformByOpenGLForDrawing(); 00333 } 00334 00335 glPushAttrib( GL_ALL_ATTRIB_BITS ); 00336 glDisable( GL_LIGHTING ); 00337 std::vector< Hexahedron<T> >::iterator it = m_vElements.begin(); 00338 while ( it != m_vElements.end() ) { 00339 it->DrawUndeformedMesh(); 00340 ++it; 00341 } 00342 glPopAttrib(); 00343 00344 if ( m_pTrx ) { 00345 glPopMatrix(); 00346 } 00347 } 00348 00349 //----------------------------------------------------------------------------- 00350 template <typename T> 00351 void MeshHexahedra<T>::DrawDeformedMesh () 00352 { 00353 if ( m_pTrx ) { 00354 glPushMatrix(); 00355 m_pTrx->TransformByOpenGLForDrawing(); 00356 } 00357 00358 glPushAttrib( GL_ALL_ATTRIB_BITS ); 00359 glDisable( GL_LIGHTING ); 00360 std::vector< Hexahedron<T> >::iterator it = m_vElements.begin(); 00361 while ( it != m_vElements.end() ) { 00362 it->DrawDeformedMesh(); 00363 ++it; 00364 } 00365 glPopAttrib(); 00366 00367 if ( m_pTrx ) { 00368 glPopMatrix(); 00369 } 00370 } 00371 00372 //----------------------------------------------------------------------------- 00373 #ifdef TAPs_ADD_INTERACTIONS 00374 template <typename T> 00375 void MeshHexahedra<T>::DrawInteractionForces () 00376 { 00377 if ( m_pTrx ) { 00378 glPushMatrix(); 00379 m_pTrx->TransformByOpenGLForDrawing(); 00380 } 00381 00382 // Point forces 00383 ForceListsPtr<T>::TypeDef_PointForces::const_iterator pf = m_ForceLists.PointForces.begin(); 00384 glPushAttrib( GL_ALL_ATTRIB_BITS ); 00385 glLineWidth( 1 ); 00386 glDisable( GL_LIGHTING ); 00387 glBegin( GL_LINES ); 00388 while ( pf != m_ForceLists.PointForces.end() ) { 00389 Vector3<T> pos = m_vElements[ (**pf).GetID() ].ComputeDeformedPositionBasedOnCoordinates( 00390 (**pf).RefToPosition()[0], (**pf).RefToPosition()[1], (**pf).RefToPosition()[2] ); 00391 00392 //std::cout << *(m_vElements[ (**pf).GetID() ].DeformedNode( 6 )) << "\n"; 00393 //std::cout << "pos: " << pos << "\n"; 00394 //std::cout << "force: " << (**pf).RefToForce() << "\n"; 00395 00396 glColor3f( 0, 1, 0 ); 00397 glVertex3fv( pos.GetDataFloat() ); 00398 glColor3f( 1, 0, 0 ); 00399 glVertex3fv( ((**pf).RefToForce()+pos).GetDataFloat() ); 00400 ++pf; 00401 } 00402 glEnd(); 00403 glPopAttrib(); 00404 00405 // CD forces 00406 pf = m_ForceLists.CDForces.begin(); 00407 glPushAttrib( GL_ALL_ATTRIB_BITS ); 00408 glLineWidth( 1 ); 00409 glDisable( GL_LIGHTING ); 00410 glBegin( GL_LINES ); 00411 while ( pf != m_ForceLists.CDForces.end() ) { 00412 Vector3<T> pos = m_vElements[ (**pf).GetID() ].ComputeDeformedPositionBasedOnCoordinates( 00413 (**pf).RefToPosition()[0], (**pf).RefToPosition()[1], (**pf).RefToPosition()[2] ); 00414 00415 //std::cout << *(m_vElements[ (**pf).GetID() ].DeformedNode( 6 )) << "\n"; 00416 //std::cout << "pos: " << pos << "\n"; 00417 //std::cout << "force: " << (**pf).RefToForce() << "\n"; 00418 00419 glColor3f( 0, 1, 0 ); 00420 glVertex3fv( pos.GetDataFloat() ); 00421 glColor3f( 1, 0, 0 ); 00422 glVertex3fv( ((**pf).RefToForce()+pos).GetDataFloat() ); 00423 ++pf; 00424 } 00425 glEnd(); 00426 glPopAttrib(); 00427 00428 if ( m_pTrx ) { 00429 glPopMatrix(); 00430 } 00431 } 00432 #endif//TAPs_ADD_INTERACTIONS 00433 //----------------------------------------------------------------------------- 00434 #endif // OpenGL 00435 //============================================================================= 00436 00437 00438 00439 00440 //----------------------------------------------------------------------------- 00441 //============================================================================= 00442 END_NAMESPACE_TAPs__FEM 00443 //34567890123456789012345678901234567890123456789012345678901234567890123456789 00444 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----