SpringRef< T > Class Template Reference

#include <TAPsSpringRef.hpp>

Collaboration diagram for SpringRef< T >:

Collaboration graph
[legend]

List of all members.

Public Member Functions

void CalAndSetForce ()
GetConstantK () const
GetCurrentLength () const
GetDampingD () const
void GetForce (Vector3< T > &F1, Vector3< T > &F2) const
Vector3< T > GetForce1 () const
Vector3< T > GetForce2 () const
ParticleRef< T > const & GetParticleOne () const
ParticleRef< T > & GetParticleOne ()
ParticleRef< T > const & GetParticleTwo () const
ParticleRef< T > & GetParticleTwo ()
GetRestLengthL () const
void SetConstantK (T Ks)
void SetDampingD (T Kd)
void SetRestLengthL (T length)
 SpringRef (ParticleRef< T > &P1, ParticleRef< T > &P2, T k, T d, T l, int hops=1)
 SpringRef (ParticleRef< T > &P1, ParticleRef< T > &P2, T k, T d, int hops=1)
 ~SpringRef ()

Static Public Member Functions

static void SpringsCreation (HEVertexList< T > *meshVertex, std::list< int > &vertexNo, std::list< ParticleRef< T > > &particleList, T mass, std::list< SpringRef< T > > &springNo, T Ks, T Kd, int hopDistance=1)
static void SpringsCreation (XVertex< T > *meshVertex, int *vertexNo, ParticleRef< T > *particleNo, T mass, SpringRef< T > *springNo, T Ks, T Kd, int hopDistance=1)
static void SpringsCreation (Vertex< T > *meshVertex, int *vertexNo, ParticleRef< T > *particleNo, T mass, SpringRef< T > *springNo, T Ks, T Kd, int hopDistance=1)

Private Member Functions

SpringRef< T > const & operator= (SpringRef< T > const &S)

Private Attributes

int m_iNumHops
ParticleRef< T > * m_refP1
ParticleRef< T > * m_refP2
m_tD
m_tK
m_tL

Friends

std::ostream & operator<< (std::ostream &output, SpringRef< T > const &S)


Detailed Description

template<typename T>
class SpringRef< T >

Definition at line 19 of file TAPsSpringRef.hpp.


Constructor & Destructor Documentation

template<typename T>
SpringRef< T >::SpringRef ( ParticleRef< T > &  P1,
ParticleRef< T > &  P2,
k,
d,
int  hops = 1 
) [inline]

Definition at line 40 of file TAPsSpringRef.cpp.

00045     : 
00046     m_refP1( &P1 ), 
00047     m_refP2( &P2 ), 
00048     m_tK( k ), 
00049     m_tD( d ), 
00050     m_iNumHops( hops )
00051 {
00052     T x = P2.GetPosition().GetX() - P1.GetPosition().GetX();
00053     T y = P2.GetPosition().GetY() - P1.GetPosition().GetY();
00054     T z = P2.GetPosition().GetZ() - P1.GetPosition().GetZ();
00055     m_tL = sqrt( x*x + y*y + z*z );
00056 }

template<typename T>
BEGIN_NAMESPACE_TAPs SpringRef< T >::SpringRef ( ParticleRef< T > &  P1,
ParticleRef< T > &  P2,
k,
d,
l,
int  hops = 1 
) [inline]

Definition at line 23 of file TAPsSpringRef.cpp.

00028     : 
00029     m_refP1( &P1 ), 
00030     m_refP2( &P2 ), 
00031     m_tK( k ), 
00032     m_tD( d ), 
00033     m_tL( l ), 
00034     m_iNumHops( hops )
00035 {}

template<typename T>
SpringRef< T >::~SpringRef (  )  [inline]

Definition at line 60 of file TAPsSpringRef.cpp.

00061 {}


Member Function Documentation

template<typename T>
void SpringRef< T >::CalAndSetForce (  )  [inline]

Definition at line 184 of file TAPsSpringRef.cpp.

00185 {
00186     Vector3<T> F2 = GetForce2();
00187     if ( m_refP2->GetFixStatus() ) {
00188         m_refP2->SetVelocity( 0, 0, 0 );
00189         m_refP2->SetForce( 0, 0 , 0 );
00190     }
00191     else {
00192         m_refP2->SetForce( m_refP2->GetForce() + F2 );
00193     }
00194     if ( m_refP1->GetFixStatus() ) {
00195         m_refP1->SetVelocity( 0, 0, 0 );
00196         m_refP1->SetForce( 0, 0 , 0 );
00197     }
00198     else {
00199         m_refP1->SetForce( m_refP1->GetForce() - F2 );
00200     }
00201 }

template<typename T>
T SpringRef< T >::GetConstantK (  )  const [inline]

Definition at line 228 of file TAPsSpringRef.cpp.

00229 {   return m_tK;    }

template<typename T>
T SpringRef< T >::GetCurrentLength (  )  const [inline]

Definition at line 243 of file TAPsSpringRef.cpp.

00244 {   return ( m_refP1->GetPosition() - m_refP2->GetPosition() ).Length();    }

template<typename T>
T SpringRef< T >::GetDampingD (  )  const [inline]

Definition at line 233 of file TAPsSpringRef.cpp.

00234 {   return m_tD;    }

template<typename T>
void SpringRef< T >::GetForce ( Vector3< T > &  F1,
Vector3< T > &  F2 
) const [inline]

Definition at line 175 of file TAPsSpringRef.cpp.

00176 {
00177     F2 = GetForce2();
00178     F1 = -F2;
00179 }

template<typename T>
Vector3< T > SpringRef< T >::GetForce1 (  )  const [inline]

Definition at line 67 of file TAPsSpringRef.cpp.

00068 {
00069 
00070     std::cout << "OBSOLETED: GetForce1() should not be called" << std::endl;
00071     exit( 1 );
00072 
00073     // Not Home Spring
00074     if ( m_iNumHops > 0 ) {
00075         // Local Variables ------------------------------------------
00076         // spring current length vector
00077         Vector3<T> cL = ( m_refP1->GetPosition() - m_refP2->GetPosition() );
00078         // spring current length scalar
00079         T scl = cL.Length();
00080         cL /= scl;  // normalize the length vector
00081         // velocity difference of the two particles linked by the spring
00082         Vector3<T> V = ( m_refP1->GetVelocity() - m_refP2->GetVelocity() );
00083         //-----------------------------------------------------------
00084         // Formula from Physically Based Modeling (Siggraph 2001 Course Note)
00085         // F1 = -{Ks(l - r) + Kd[(V1-V2)*L]/l}*L/l
00086         // F2 = -F1
00087         //   where Ks = spring stiffness, Kd = spring damping,
00088         //     V1 and V2 are velocity of particles linked by the spring
00089         //     r = spring rest length
00090         //     L = vector of difference of positions of particle#1 and #2
00091         //     l = magnitude of L
00092         return ( ( m_tK * (scl - m_tL) ) + ( m_tD * V * cL ) ) * cL;
00093     }
00094     // Home Spring
00095     else {
00096         // Local Variables ------------------------------------------
00097         // spring current length vector
00098         Vector3<T> cL = ( m_refP1->GetPosition() - m_refP2->GetPosition() );
00099         // spring current length scalar
00100         T scl = cL.Length();
00101         if ( scl == TAPs::Math<T>::ZERO ) return TAPs::CGMath<T>::ZeroVector;
00102         cL /= scl;  // normalize the length vector
00103         // velocity difference of the two particles linked by the spring
00104         Vector3<T> V = ( m_refP1->GetVelocity() - m_refP2->GetVelocity() );
00105         //-----------------------------------------------------------
00106         // Formula from Physically Based Modeling (Siggraph 2001 Course Note)
00107         // F1 = -{Ks(l - r) + Kd[(V1-V2)*L]/l}*L/l
00108         // F2 = -F1
00109         //   where Ks = spring stiffness, Kd = spring damping,
00110         //     V1 and V2 are velocity of particles linked by the spring
00111         //     r = spring rest length
00112         //     L = vector of difference of positions of particle#1 and #2
00113         //     l = magnitude of L
00114         //return ( ( m_tK * (scl - m_tL) ) + ( m_tD * V * cL ) ) * cL;
00115         return ( ( m_tK * scl ) + ( m_tD * V * cL ) ) * cL; // since m_tL is zero
00116     }
00117 }

template<typename T>
Vector3< T > SpringRef< T >::GetForce2 (  )  const [inline]

Definition at line 123 of file TAPsSpringRef.cpp.

00124 {
00125     // Not Home Spring
00126     if ( m_iNumHops > 0 ) {
00127         // Local Variables ------------------------------------------
00128         // spring current length vector
00129         Vector3<T> cL = ( m_refP1->GetPosition() - m_refP2->GetPosition() );
00130         // spring current length scalar
00131         T scl = cL.Length();
00132         cL /= scl;  // normalize the length vector
00133         // velocity difference of the two particles linked by the spring
00134         Vector3<T> V = ( m_refP1->GetVelocity() - m_refP2->GetVelocity() );
00135         //-----------------------------------------------------------
00136         // Formula from Physically Based Modeling (Siggraph 2001 Course Note)
00137         // F1 = -{Ks(l - r) + Kd[(V1-V2)*L]/l}*L/l
00138         // F2 = -F1
00139         //   where Ks = spring stiffness, Kd = spring damping,
00140         //     V1 and V2 are velocity of particles linked by the spring
00141         //     r = spring rest length
00142         //     L = vector of difference of positions of particle#1 and #2
00143         //     l = magnitude of L
00144         return ( ( m_tK * (scl - m_tL) ) + ( m_tD * V * cL ) ) * cL;
00145     }
00146     // Home Spring
00147     else {
00148         // Local Variables ------------------------------------------
00149         // spring current length vector
00150         Vector3<T> cL = ( m_refP1->GetPosition() - m_refP2->GetPosition() );
00151         // spring current length scalar
00152         T scl = cL.Length();
00153         if ( scl == TAPs::Math<T>::ZERO ) return TAPs::CGMath<T>::ZeroVector;
00154         cL /= scl;  // normalize the length vector
00155         // velocity difference of the two particles linked by the spring
00156         Vector3<T> V = ( m_refP1->GetVelocity() - m_refP2->GetVelocity() );
00157         //-----------------------------------------------------------
00158         // Formula from Physically Based Modeling (Siggraph 2001 Course Note)
00159         // F1 = -{Ks(l - r) + Kd[(V1-V2)*L]/l}*L/l
00160         // F2 = -F1
00161         //   where Ks = spring stiffness, Kd = spring damping,
00162         //     V1 and V2 are velocity of particles linked by the spring
00163         //     r = spring rest length
00164         //     L = vector of difference of positions of particle#1 and #2
00165         //     l = magnitude of L
00166         //return ( ( m_tK * (scl - m_tL) ) + ( m_tD * V * cL ) ) * cL;
00167         return ( ( m_tK * scl ) + ( m_tD * V * cL ) ) * cL; // since m_tL is zero
00168     }
00169 }

template<typename T>
ParticleRef< T > const & SpringRef< T >::GetParticleOne (  )  const [inline]

Definition at line 218 of file TAPsSpringRef.cpp.

00219 {   return *m_refP1;    }

template<typename T>
ParticleRef< T > & SpringRef< T >::GetParticleOne (  )  [inline]

Definition at line 208 of file TAPsSpringRef.cpp.

00209 {   return *m_refP1;    }

template<typename T>
ParticleRef< T > const & SpringRef< T >::GetParticleTwo (  )  const [inline]

Definition at line 223 of file TAPsSpringRef.cpp.

00224 {   return *m_refP2;    }

template<typename T>
ParticleRef< T > & SpringRef< T >::GetParticleTwo (  )  [inline]

Definition at line 213 of file TAPsSpringRef.cpp.

00214 {   return *m_refP2;    }

template<typename T>
T SpringRef< T >::GetRestLengthL (  )  const [inline]

Definition at line 238 of file TAPsSpringRef.cpp.

00239 {   return m_tL;    }

template<typename T>
SpringRef<T> const& SpringRef< T >::operator= ( SpringRef< T > const &  S  )  [inline, private]

Definition at line 131 of file TAPsSpringRef.hpp.

00132     {
00133         std::cerr << "SpringRef<T> operator= must not be used!\n";
00134         exit( 1 );
00135     }

template<typename T>
void SpringRef< T >::SetConstantK ( Ks  )  [inline]

Definition at line 248 of file TAPsSpringRef.cpp.

00249 {   m_tK = Ks;  }

template<typename T>
void SpringRef< T >::SetDampingD ( Kd  )  [inline]

Definition at line 253 of file TAPsSpringRef.cpp.

00254 {   m_tD = Kd;  }

template<typename T>
void SpringRef< T >::SetRestLengthL ( length  )  [inline]

Definition at line 258 of file TAPsSpringRef.cpp.

00259 {   m_tL = length;  }

template<typename T>
void SpringRef< T >::SpringsCreation ( HEVertexList< T > *  meshVertex,
std::list< int > &  vertexNo,
std::list< ParticleRef< T > > &  particleList,
mass,
std::list< SpringRef< T > > &  springNo,
Ks,
Kd,
int  hopDistance = 1 
) [inline, static]

Definition at line 265 of file TAPsSpringRef.cpp.

00266                                             : Mesh XVertex
00267         std::list<int>  & vertexNo,   // O/P: vertex# associates Mesh XVertex w/ Spring#
00268         std::list< ParticleRef<T> > & particleList, // O/P: Particle List
00269         T                 mass,       // I/P: mass for each particle
00270         std::list< SpringRef<T> >   & springNo,   // O/P: Spring List
00271         T Ks, T Kd,                   // I/P: Spring Stiffness and Damping Constant
00272         int hopDistance               // I/P: Number of distance/rigidity for spring connection
00273 )
00274 {
00275     if ( !meshVertex )  return;
00276     //----------------------------------------------------------------
00277     HEVertex<T> * vertex = meshVertex.Head();
00278     //----------------------------------------------------------------
00279     vertexNo.clear();
00280     for ( int i = 0; i < meshVertex.Size(); ++i ) {
00281     //  vertex = 
00282     }
00283     //----------------------------------------------------------------
00284     //----------------------------------------------------------------
00285     //----------------------------------------------------------------
00286 }

template<typename T>
static void SpringRef< T >::SpringsCreation ( XVertex< T > *  meshVertex,
int *  vertexNo,
ParticleRef< T > *  particleNo,
mass,
SpringRef< T > *  springNo,
Ks,
Kd,
int  hopDistance = 1 
) [static]

template<typename T>
static void SpringRef< T >::SpringsCreation ( Vertex< T > *  meshVertex,
int *  vertexNo,
ParticleRef< T > *  particleNo,
mass,
SpringRef< T > *  springNo,
Ks,
Kd,
int  hopDistance = 1 
) [static]


Friends And Related Function Documentation

template<typename T>
std::ostream& operator<< ( std::ostream &  output,
SpringRef< T > const &  S 
) [friend]

Definition at line 23 of file TAPsSpringRef.hpp.

00024     {
00025         output  << "Spring<" << typeid(T).name() << "> ==> "
00026                 << "\n  -------START--SPRING_VERTEX--INFO-------"
00027                 << "\n  Particle#1: " << *(S.m_refP1)
00028                 << "\n  Particle#2: " << *(S.m_refP2)
00029                 << "\n  K Constant: " << S.m_tK
00030                 << "\n  D Damping:  " << S.m_tD
00031                 << "\n  L Length:   " << S.m_tL
00032                 << "\n  Force#1:      " << S.GetForce1()
00033                 << "\n  Force#2:      " << S.GetForce2()
00034                 << "\n  Current Length: " << S.GetCurrentLength()
00035                 << "\n  --------END--SPRING_VERTEX--INFO--------\n";
00036         return output;
00037     }


Member Data Documentation

template<typename T>
int SpringRef< T >::m_iNumHops [private]

Definition at line 47 of file TAPsSpringRef.hpp.

template<typename T>
ParticleRef<T>* SpringRef< T >::m_refP1 [private]

Definition at line 41 of file TAPsSpringRef.hpp.

template<typename T>
ParticleRef<T>* SpringRef< T >::m_refP2 [private]

Definition at line 42 of file TAPsSpringRef.hpp.

template<typename T>
T SpringRef< T >::m_tD [private]

Definition at line 44 of file TAPsSpringRef.hpp.

template<typename T>
T SpringRef< T >::m_tK [private]

Definition at line 43 of file TAPsSpringRef.hpp.

template<typename T>
T SpringRef< T >::m_tL [private]

Definition at line 45 of file TAPsSpringRef.hpp.


The documentation for this class was generated from the following files:

Generated on Mon Oct 13 11:45:57 2008 for TAPs by  doxygen 1.5.6