TAPs 0.7.7.3
TAPsFEMMesh.hpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsFEMMesh.hpp
00003 ******************************************************************************/
00007 /******************************************************************************
00008 SUKITTI PUNAK   (12/15/2009)
00009 UPDATE          (10/27/2010)
00010 ******************************************************************************/
00011 #ifndef TAPs_FEM_MESH_HPP
00012 #define TAPs_FEM_MESH_HPP
00013 
00014 #include "TAPsFEMElement.hpp"
00015 
00017 // REMARK:
00018 //   The sparse (nonsymmetric) matrix is used instead of the sparse sysmtetric matrix, 
00019 //   because it provides more flexibility.
00020 //   Also for nonlinear FEM, the stiffness matrix is no longer symmetric.
00022 
00023 #include "../DataStructure/TAPsSparseMatrix_Matrix3x3.hpp"
00024 
00026 #define TAPs_SIM_DYNAMIC_SYSTEM
00027 
00028 #ifdef  TAPs_SIM_DYNAMIC_SYSTEM
00029 #endif//TAPs_SIM_DYNAMIC_SYSTEM
00030 
00032 #define TAPs_ADD_INTERACTIONS
00033 
00034 #ifdef  TAPs_ADD_INTERACTIONS
00035     #include "../Physics/TAPsForces.hpp"
00036 #endif//TAPs_ADD_INTERACTIONS
00037 
00038 #include "../Support/TAPsTransformationSupport.hpp"
00039 
00040 BEGIN_NAMESPACE_TAPs__FEM
00041 //=============================================================================
00042 template <typename T>
00043 class Mesh {
00044 //=============================================================================
00045 public:
00046     // Member Functions -------------------------------------------------------
00048     friend std::ostream & operator<< ( std::ostream &output, Mesh<T> const &obj )
00049     {
00050         output << obj.StrInfo();
00051         return output;
00052     }
00053     //-------------------------------------------------------------------------
00056     Mesh ();
00058     //Mesh ( Mesh<T> const &orig );
00060     virtual ~Mesh ();
00061     //-------------------------------------------------------------------------
00063     virtual std::string StrInfo () const = 0;
00064     //-------------------------------------------------------------------------
00066     //Mesh<T> & operator= ( Mesh<T> const &orig ) = 0;
00067 
00068     //-------------------------------------------------------------------------
00069     // Operations
00070 
00072     std::vector< Vector3<T> > & RetListOfDeformedMeshNodes ()   { return m_vDeformedMeshNodes; }
00073 
00075     std::vector< Vector3<T> > & RetListOfUndeformedMeshNodes () { return m_vUndeformedMeshNodes; }
00076 
00078     //inline virtual void ResetToDeformedState () = 0;
00079 
00081     inline virtual void ResetToUndeformedState () = 0;
00082 
00084     virtual void SetSizeOfStiffnessMatrix ();
00085 
00087     virtual void AssembleStiffnessMatrix () = 0;
00088 
00090     virtual void UpdateStrainDisplacementMatrix () = 0;
00091 
00092     //-------------------------------------------------------------------------
00093     // Get/Set
00094 
00096     SparseMatrix_Matrix3x3<T> const & StiffnessMatrix () const { return Mstiff; }
00097 
00099     inline unsigned int GetNumOfNodes () const;
00100 
00102     inline virtual Vector3<T> const & ForceAtNode ( unsigned int node ) const;
00104     inline Vector3<T> & ForceAtNode ( unsigned int node );
00105 
00107     inline virtual Vector3<T> const & FilterAtNode ( unsigned int node ) const;
00109     inline Vector3<T> & FilterAtNode ( unsigned int node );
00110 
00112     inline Vector3<T> const & OrigPositionOfNode ( unsigned int node ) const;
00114     inline Vector3<T> & OrigPositionOfNode ( unsigned int node );
00115 
00117     inline Vector3<T> const & CurrPositionOfNode ( unsigned int node ) const;
00119     inline Vector3<T> & CurrPositionOfNode ( unsigned int node );
00120 
00122     inline void SetTransformationSupportPointer ( TransformationSupport<T> * pTrx ) { m_pTrx = pTrx; }
00124     inline TransformationSupport<T> const & RefToTransformationSupport () const { return *m_pTrx; }
00126     inline TransformationSupport<T> &       RefToTransformationSupport ()       { return *m_pTrx; }
00127 
00128     //---------------------------------------------------------------
00129     // Prescribed Displacements
00130 
00132     inline void FixNode ( unsigned int node, bool b );
00133 
00135     inline void FixNode ( unsigned int node );
00136 
00138     inline void UnfixNode ( unsigned int node );
00139 
00141     inline void ToggleFixUnfixOfNode ( unsigned int node );
00142 
00144     inline bool IsFixedNode ( unsigned int node );
00145 
00147     inline void SetFixedDisplacementOfNode ( unsigned int node, Vector3<T> const & u );
00149     inline void SetFixedDisplacementOfNode ( unsigned int node, T x, T y, T z );
00150 
00151 
00152 #ifdef  TAPs_SIM_DYNAMIC_SYSTEM
00153 
00154     inline T GetTimeStep () const;
00156     inline void SetTimeStep ( T timestep );
00157 
00159     inline Vector3<T> const & MassOfNode ( unsigned int node ) const;
00161     inline Vector3<T> & MassOfNode ( unsigned int node );
00162 
00164     inline Vector3<T> const & CurrentVelocityOfNode ( unsigned int node ) const;
00166     inline Vector3<T> & CurrentVelocityOfNode ( unsigned int node );
00168     inline Vector3<T> const & NextVelocityOfNode ( unsigned int node ) const;
00170     inline Vector3<T> & NextVelocityOfNode ( unsigned int node );
00171 
00173     inline T GetDampingMass () const;
00175     inline void SetDampingMass ( T d );
00176 
00178     inline T GetDampingStiffness () const;
00180     inline void SetDampingStiffness ( T d );
00181 
00183     inline void ResetCurrentVelocities ();
00184 
00185 #endif//TAPs_SIM_DYNAMIC_SYSTEM
00186 
00187 
00188     // Virtual Fns ------------------------------
00189 
00191     inline virtual unsigned int GetNumOfElements () const = 0;
00192 
00194     inline virtual Element<T> const &   RefToElement ( unsigned int i ) const = 0;
00196     inline virtual Element<T> &         RefToElement ( unsigned int i ) = 0;
00197 
00198     //-------------------------------------------------------------------------
00199     // Simulation
00200 
00202     virtual void AllocateDataForSimulation ( T mass = 1 );
00203 
00205     unsigned char GetIterationLimit () const    { return m_iIterationLimit; }
00207     void SetIterationLimit ( unsigned char limit ) { m_iIterationLimit = limit; }
00208 
00210     T GetErrorThreshold () const    { return m_tErrorThreshold; }
00212     void SetErrorThreshold ( T error ) { m_tErrorThreshold = error; }
00213 
00220     void ClearAllNodeForces ();
00221 
00222     //-------------------------------------------------------------------------
00223     // Checking
00224 
00226     virtual std::string CheckVolumeOfEachElement () = 0;
00227 
00228     //-------------------------------------------------------------------------
00229 
00231     virtual void AdvanceSimulationStatic ();
00232 
00239     virtual void AdvanceSimulationStatic_woFixedDisplacementNodes ();
00240 
00241 #ifdef  TAPs_SIM_DYNAMIC_SYSTEM
00242 
00244     virtual void AdvanceSimulationDynamic ();
00245 
00252     virtual void AdvanceSimulationDynamic_woFixedDisplacementNodes ();
00253 
00254 #endif//TAPs_SIM_DYNAMIC_SYSTEM
00255 
00256 protected:
00260     void MPCGSolver (
00261         SparseMatrix_Matrix3x3<T> const &A,     
00262         std::vector< Vector3<T> > const &x,     
00263         std::vector< Vector3<T> > const &b,     
00264         std::vector< Vector3<T> > &x_out,       
00265         std::vector< Vector3<T> > const &ft,    
00266         std::vector< Vector3<T> > const &P,     
00267         int iterationLimit = 100,               
00268         T errorThreshold = 1E-10                
00269     );
00270 
00271     // Data Members -----------------------------------------------------------
00272 
00273 //=============================================================================
00274 protected:
00275     // Member Functions -------------------------------------------------------
00276 
00277     // Simulation -------------------------------
00279     inline void UpdateDisplacementVector ();
00281     inline void UpdateDisplacementVector_wFixedDisplacementNodes ();
00283     inline void UpdateDeformedMeshNodes ();
00284 
00286     inline void UpdateFixedDisplacements ();
00287 
00288     // Data Members -----------------------------------------------------------
00289 
00290     // Stiffness matrix is always square.
00291     SparseMatrix_Matrix3x3<T>   Mstiff;     
00292     SparseMatrix_Matrix3x3<T>   Mstiff_2;   
00293 
00294     // Mesh nodes determines the size of the stiffness matrix.
00295     std::vector< Vector3<T> >   m_vDeformedMeshNodes;       
00296     std::vector< Vector3<T> >   m_vUndeformedMeshNodes;     
00297 
00298     // Simulation -------------------------------
00299 
00300     // For prescribed fixed displacements.
00301     // The size of these data have to be the same as the size of the stiffness matrix.
00302     std::vector< bool >         m_FixedNodes;           
00303     std::vector< Vector3<T> >   m_FixedDisplacements;   
00304 
00305     // These data are for SparseMatrix_Matrix3x3<T>::MPCGSolver function.
00306     // The size of these data have to be the same as the size of the stiffness matrix
00307     std::vector< Vector3<T> >   m_Filters;  
00308     std::vector< Vector3<T> >   m_Forces;   
00309     std::vector< Vector3<T> >   m_u;        
00310     std::vector< Vector3<T> >   m_u_out;    
00311     std::vector< Vector3<T> >   m_Precond;  
00312 
00313     unsigned char   m_iIterationLimit;  
00314     T               m_tErrorThreshold;  
00315 
00316 //===================================================================
00317 // For dynamic system
00318 #ifdef  TAPs_SIM_DYNAMIC_SYSTEM
00319 //-------------------------------------------------------------------
00320     T                           m_tTimeStep;            
00321     std::vector< Vector3<T> >   m_vNodeMass;            
00322     std::vector< Vector3<T> >   m_vNodeVelocities[2];   
00323     unsigned char               m_currVelIdx;           
00324     unsigned char               m_nextVelIdx;           
00325 
00326     T   m_tNodeDamping_Alpha;   
00327     T   m_tNodeDamping_Beta;    
00328 
00334     SparseMatrix_Matrix3x3<T>   m_A;    
00335     std::vector< Vector3<T> >   m_b;    
00336 
00340     inline void UpdateAandB ( SparseMatrix_Matrix3x3<T> & Mstiff );
00341 //-------------------------------------------------------------------
00342 #endif//TAPs_SIM_DYNAMIC_SYSTEM
00343 //===================================================================
00344 
00345 
00346 //=============================================================================
00347 private:
00348     // Member Functions -------------------------------------------------------
00349 
00350     // For MPCGSolver
00351     std::vector< Vector3<T> > v;    
00352     std::vector< Vector3<T> > Pinv; 
00353     std::vector< Vector3<T> > r;    
00354     std::vector< Vector3<T> > s;    
00355     std::vector< Vector3<T> > c;    
00356     std::vector< Vector3<T> > q;    
00357 
00358     /*
00359     // DEBUG
00360     void Print ( std::vector< Vector3<T> > const & v ) {
00361         std::cout << "V:\n";
00362         for ( unsigned int i = 0; i < v.size(); ++i ) {
00363             std::cout << "\t" << v[i] << "\n";
00364         }
00365         std::cout << "\n";
00366     }
00367     //*/
00368 
00369     // Data Members -----------------------------------------------------------
00370 //=============================================================================
00371 
00372 
00373 //=============================================================================
00374 // For interactions
00375 #ifdef  TAPs_ADD_INTERACTIONS
00376 //-----------------------------------------------------------------------------
00377 public:
00378     // Member Functions ---------------------------------------------
00379 
00385     inline virtual void AddPointForce ( PointForce<T> * const ptrPtForce );
00389     inline virtual void AddPointForceInLocalCoordinates ( PointForce<T> * const ptrPtForce );
00390 
00392     inline virtual void RemovePointForce ( PointForce<T> * const ptrPtForce );
00393 
00399     inline virtual void AddCDForce ( PointForce<T> * const ptrCDForce );
00403     inline virtual void AddCDForceInLocalCoordinates ( PointForce<T> * const ptrCDForce );
00404 
00406     inline virtual void RemoveCDForce ( PointForce<T> * const ptrCDForce );
00407 
00413     inline virtual void AddConnectionForce ( PointForce<T> * const ptrConnectionForce );
00417     inline virtual void AddConnectionForceInLocalCoordinates ( PointForce<T> * const ptrConnectionForce );
00418 
00420     inline virtual void RemoveConnectionForce ( PointForce<T> * const ptrConnectionForce );
00421 
00427     void ClearAllPointLoads ();
00428 
00434     void ClearAllCDLoads ();
00435 
00441     void ClearAllConnectionLoads ();
00442 
00448     void ClearAllAppliedLoads ();
00449 
00450     // Data Members -------------------------------------------------
00451 
00452 protected:
00453     // Member Functions ---------------------------------------------
00454 
00455     // Data Members -------------------------------------------------
00456     ForceListsPtr<T>    m_ForceLists;   
00457 
00461     inline virtual void ApplyAllLoads ();
00462 
00464     inline virtual void ApplyPointLoad ( PointForce<T> const * const ptrPtForce ) = 0;
00465 
00466     TransformationSupport<T> *  m_pTrx; 
00467 
00468 private:
00469     // Member Functions ---------------------------------------------
00470     // Data Members -------------------------------------------------
00471 //-----------------------------------------------------------------------------
00472 #endif//TAPs_ADD_INTERACTIONS
00473 //=============================================================================
00474 
00475 
00476 #if defined(__gl_h_) || defined(__GL_H__)
00477 public:
00479     void DrawFixedNodes ();
00480 
00482     virtual void Draw () = 0;
00483 
00485     virtual void DrawUndeformedMesh () = 0;
00486 
00488     virtual void DrawDeformedMesh () = 0;
00489 
00490     #ifdef  TAPs_ADD_INTERACTIONS
00491 
00492         virtual void DrawInteractionForces () = 0;
00493     #endif//TAPs_ADD_INTERACTIONS
00494 #endif
00495 
00496 //=============================================================================
00497 }; // END CLASS Mesh
00498 //=============================================================================
00499 END_NAMESPACE_TAPs__FEM
00500 //-----------------------------------------------------------------------------
00502 #include "TAPsFEMMesh.cpp"
00503 
00505 // Include definition if TAPs_USE_EXPORT is not defined
00506 //#if !defined( TAPs_USE_EXPORT )
00507 //  #include "TAPsFEMMesh.cpp"
00508 //#endif
00509 //-----------------------------------------------------------------------------
00510 #endif
00511 //34567890123456789012345678901234567890123456789012345678901234567890123456789
00512 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines