TAPs 0.7.7.3
TAPsFEMHexahedron.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsFEMHexahedron.cpp
00003 ******************************************************************************/
00007 /******************************************************************************
00008 SUKITTI PUNAK   (12/30/2009)
00009 UPDATE          (07/01/2010)
00010 ******************************************************************************/
00011 #include "TAPsFEMHexahedron.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 // Static Data Members
00019 //-----------------------------------------------------------------------------
00020 
00021 template <typename T> bool Hexahedron<T>::g_Is1PtGaussPointInit = false;
00022 template <typename T> bool Hexahedron<T>::g_Is2PtGaussPointInit = false;
00023 template <typename T> T Hexahedron<T>::g_1PtGauss_Der[8*3];
00024 template <typename T> T Hexahedron<T>::g_2PtGauss_Der[8*3*8];
00025 
00026     // For finding an approximated parametric coordinates from a global coordinates
00027 template <typename T> const int Hexahedron<T>::MAX_ITERATION = 10;
00028 template <typename T> const T   Hexahedron<T>::ERROR_THRESHOLD = 1E-3;
00029 template <typename T> const T   Hexahedron<T>::NEG_BOUND = -1 - ERROR_THRESHOLD;
00030 template <typename T> const T   Hexahedron<T>::POS_BOUND =  1 + ERROR_THRESHOLD;
00031 template <typename T> const T   Hexahedron<T>::DIVERGENCE_THRESHOLD = 1E6;
00032 
00033 
00034 //-----------------------------------------------------------------------------
00035 // Static Member Functions
00036 //-----------------------------------------------------------------------------
00037 
00038 template <typename T>
00039 void Hexahedron<T>::CalAndStoreShapeFnsPartialDerivatives ( T store[], int ptNumber, T xi, T eta, T zeta )
00040 {
00041     unsigned int idx = ptNumber * 24;
00042     InterpolateShapeFunctionDerivatives( xi, eta, zeta, &(store[idx]) );
00043 }
00044 
00045 
00046 template <typename T>
00047 void Hexahedron<T>::UpdateShapeFnsPartialDerivatives_1PtGuassRule ()
00048 {
00049     if ( g_Is1PtGaussPointInit )    return;
00050     g_Is1PtGaussPointInit = true;
00051 
00052     // 1-point Gauss quadrature rule has 2.0 weight at 0 point
00053     CalAndStoreShapeFnsPartialDerivatives( g_1PtGauss_Der, 0, 0, 0, 0 );
00054 }
00055 
00056 
00057 template <typename T>
00058 void Hexahedron<T>::UpdateShapeFnsPartialDerivatives_2PtGuassRule ()
00059 {
00060     if ( g_Is2PtGaussPointInit )    return;
00061     g_Is2PtGaussPointInit = true;
00062 
00063     // 2-point Gauss quadrature rule has 1.0 wight for both -sqrt(1/3) and +sqrt(1/3) points
00064     T pt2 = sqrt(T(1)/T(3));
00065     T pt1 = -pt2;
00066 
00067     CalAndStoreShapeFnsPartialDerivatives( g_2PtGauss_Der, 0, pt1, pt1, pt1 );
00068     CalAndStoreShapeFnsPartialDerivatives( g_2PtGauss_Der, 1, pt1, pt1, pt2 );
00069     CalAndStoreShapeFnsPartialDerivatives( g_2PtGauss_Der, 2, pt1, pt2, pt1 );
00070     CalAndStoreShapeFnsPartialDerivatives( g_2PtGauss_Der, 3, pt1, pt2, pt2 );
00071     CalAndStoreShapeFnsPartialDerivatives( g_2PtGauss_Der, 4, pt2, pt1, pt1 );
00072     CalAndStoreShapeFnsPartialDerivatives( g_2PtGauss_Der, 5, pt2, pt1, pt2 );
00073     CalAndStoreShapeFnsPartialDerivatives( g_2PtGauss_Der, 6, pt2, pt2, pt1 );
00074     CalAndStoreShapeFnsPartialDerivatives( g_2PtGauss_Der, 7, pt2, pt2, pt2 );
00075 
00076     // The order of points does not effect the computation!
00077     //CalAndStoreShapeFnsPartialDerivatives( g_2PtGauss_Der, 0, pt1, pt1, pt1 );
00078     //CalAndStoreShapeFnsPartialDerivatives( g_2PtGauss_Der, 1, pt2, pt1, pt1 );
00079     //CalAndStoreShapeFnsPartialDerivatives( g_2PtGauss_Der, 2, pt2, pt2, pt1 );
00080     //CalAndStoreShapeFnsPartialDerivatives( g_2PtGauss_Der, 3, pt1, pt2, pt1 );
00081     //CalAndStoreShapeFnsPartialDerivatives( g_2PtGauss_Der, 4, pt1, pt1, pt2 );
00082     //CalAndStoreShapeFnsPartialDerivatives( g_2PtGauss_Der, 5, pt2, pt1, pt2 );
00083     //CalAndStoreShapeFnsPartialDerivatives( g_2PtGauss_Der, 6, pt2, pt2, pt2 );
00084     //CalAndStoreShapeFnsPartialDerivatives( g_2PtGauss_Der, 7, pt1, pt2, pt2 );
00085 }
00086 
00087 
00088 template <typename T>
00089 Matrix3x3<T> Hexahedron<T>::CalJacobian ( T GaussStore[], int GaussPtNumber )
00090 {
00091     int i = GaussPtNumber*24;
00092     int j = i + 8;
00093     int k = j + 8;
00094 
00095     return Matrix3x3<T>(
00096         // x_i * \frac{\partial{N_i}\partial{xi}}
00097         (*pX)[ids[0]][0]*GaussStore[i+0] + 
00098         (*pX)[ids[1]][0]*GaussStore[i+1] + 
00099         (*pX)[ids[2]][0]*GaussStore[i+2] + 
00100         (*pX)[ids[3]][0]*GaussStore[i+3] + 
00101         (*pX)[ids[4]][0]*GaussStore[i+4] + 
00102         (*pX)[ids[5]][0]*GaussStore[i+5] + 
00103         (*pX)[ids[6]][0]*GaussStore[i+6] + 
00104         (*pX)[ids[7]][0]*GaussStore[i+7], 
00105         // y_i * \frac{\partial{N_i}\partial{xi}}
00106         (*pX)[ids[0]][1]*GaussStore[i+0] + 
00107         (*pX)[ids[1]][1]*GaussStore[i+1] + 
00108         (*pX)[ids[2]][1]*GaussStore[i+2] + 
00109         (*pX)[ids[3]][1]*GaussStore[i+3] + 
00110         (*pX)[ids[4]][1]*GaussStore[i+4] + 
00111         (*pX)[ids[5]][1]*GaussStore[i+5] + 
00112         (*pX)[ids[6]][1]*GaussStore[i+6] + 
00113         (*pX)[ids[7]][1]*GaussStore[i+7], 
00114         // z_i * \frac{\partial{N_i}\partial{xi}}
00115         (*pX)[ids[0]][2]*GaussStore[i+0] + 
00116         (*pX)[ids[1]][2]*GaussStore[i+1] + 
00117         (*pX)[ids[2]][2]*GaussStore[i+2] + 
00118         (*pX)[ids[3]][2]*GaussStore[i+3] + 
00119         (*pX)[ids[4]][2]*GaussStore[i+4] + 
00120         (*pX)[ids[5]][2]*GaussStore[i+5] + 
00121         (*pX)[ids[6]][2]*GaussStore[i+6] + 
00122         (*pX)[ids[7]][2]*GaussStore[i+7], 
00123 
00124         // x_i * \frac{\partial{N_i}\partial{eta}}
00125         (*pX)[ids[0]][0]*GaussStore[j+0] + 
00126         (*pX)[ids[1]][0]*GaussStore[j+1] + 
00127         (*pX)[ids[2]][0]*GaussStore[j+2] + 
00128         (*pX)[ids[3]][0]*GaussStore[j+3] + 
00129         (*pX)[ids[4]][0]*GaussStore[j+4] + 
00130         (*pX)[ids[5]][0]*GaussStore[j+5] + 
00131         (*pX)[ids[6]][0]*GaussStore[j+6] + 
00132         (*pX)[ids[7]][0]*GaussStore[j+7], 
00133         // y_i * \frac{\partial{N_i}\partial{eta}}
00134         (*pX)[ids[0]][1]*GaussStore[j+0] + 
00135         (*pX)[ids[1]][1]*GaussStore[j+1] + 
00136         (*pX)[ids[2]][1]*GaussStore[j+2] + 
00137         (*pX)[ids[3]][1]*GaussStore[j+3] + 
00138         (*pX)[ids[4]][1]*GaussStore[j+4] + 
00139         (*pX)[ids[5]][1]*GaussStore[j+5] + 
00140         (*pX)[ids[6]][1]*GaussStore[j+6] + 
00141         (*pX)[ids[7]][1]*GaussStore[j+7], 
00142         // z_i * \frac{\partial{N_i}\partial{eta}}
00143         (*pX)[ids[0]][2]*GaussStore[j+0] + 
00144         (*pX)[ids[1]][2]*GaussStore[j+1] + 
00145         (*pX)[ids[2]][2]*GaussStore[j+2] + 
00146         (*pX)[ids[3]][2]*GaussStore[j+3] + 
00147         (*pX)[ids[4]][2]*GaussStore[j+4] + 
00148         (*pX)[ids[5]][2]*GaussStore[j+5] + 
00149         (*pX)[ids[6]][2]*GaussStore[j+6] + 
00150         (*pX)[ids[7]][2]*GaussStore[j+7], 
00151 
00152         // x_i * \frac{\partial{N_i}\partial{zeta}}
00153         (*pX)[ids[0]][0]*GaussStore[k+0] + 
00154         (*pX)[ids[1]][0]*GaussStore[k+1] + 
00155         (*pX)[ids[2]][0]*GaussStore[k+2] + 
00156         (*pX)[ids[3]][0]*GaussStore[k+3] + 
00157         (*pX)[ids[4]][0]*GaussStore[k+4] + 
00158         (*pX)[ids[5]][0]*GaussStore[k+5] + 
00159         (*pX)[ids[6]][0]*GaussStore[k+6] + 
00160         (*pX)[ids[7]][0]*GaussStore[k+7], 
00161         // y_i * \frac{\partial{N_i}\partial{zeta}}
00162         (*pX)[ids[0]][1]*GaussStore[k+0] + 
00163         (*pX)[ids[1]][1]*GaussStore[k+1] + 
00164         (*pX)[ids[2]][1]*GaussStore[k+2] + 
00165         (*pX)[ids[3]][1]*GaussStore[k+3] + 
00166         (*pX)[ids[4]][1]*GaussStore[k+4] + 
00167         (*pX)[ids[5]][1]*GaussStore[k+5] + 
00168         (*pX)[ids[6]][1]*GaussStore[k+6] + 
00169         (*pX)[ids[7]][1]*GaussStore[k+7], 
00170         // z_i * \frac{\partial{N_i}\partial{zeta}}
00171         (*pX)[ids[0]][2]*GaussStore[k+0] + 
00172         (*pX)[ids[1]][2]*GaussStore[k+1] + 
00173         (*pX)[ids[2]][2]*GaussStore[k+2] + 
00174         (*pX)[ids[3]][2]*GaussStore[k+3] + 
00175         (*pX)[ids[4]][2]*GaussStore[k+4] + 
00176         (*pX)[ids[5]][2]*GaussStore[k+5] + 
00177         (*pX)[ids[6]][2]*GaussStore[k+6] + 
00178         (*pX)[ids[7]][2]*GaussStore[k+7] 
00179     );
00180 }
00181 
00182 //-----------------------------------------------------------------------------
00183 //=============================================================================
00184 
00185 
00186 //=============================================================================
00187 // Constructors
00188 //-----------------------------------------------------------------------------
00189 template <typename T>
00190 Hexahedron<T>::Hexahedron ( 
00191         std::vector< Vector3<T> > * deformedNodes,      
00192         std::vector< Vector3<T> > * undeformedNodes,    
00193         T YoungModulus,     
00194         T PoissionRatio,    
00195         unsigned int globalNode0,   
00196         unsigned int globalNode1,   
00197         unsigned int globalNode2,   
00198         unsigned int globalNode3,   
00199         unsigned int globalNode4,   
00200         unsigned int globalNode5,   
00201         unsigned int globalNode6,   
00202         unsigned int globalNode7    
00203 ) : Element( deformedNodes, undeformedNodes, YoungModulus, PoissionRatio )
00204 {
00205     ids[0] = globalNode0;
00206     ids[1] = globalNode1;
00207     ids[2] = globalNode2;
00208     ids[3] = globalNode3;
00209     ids[4] = globalNode4;
00210     ids[5] = globalNode5;
00211     ids[6] = globalNode6;
00212     ids[7] = globalNode7;
00213     CalUndeformedVolume();  // the result volume is stored in Volume (the property (undeformed) for volume)
00214     UpdateElasticMatrixElements();  // update the elastic matrix due to Young's modulus, Poisson's ratio, and (undeformed) volume
00215 
00216     // Strain Displacement Matrices are computed and never stored
00217     // Therefore, they are computed inside UpdateStiffnessMatrixElements function
00218     //UpdateStrainDisplacementMatrixElements(); // update the elements of the strain-displacement matrix
00219 
00220     UpdateStiffnessMatrixElements();    // update all 16 sub stiffness matrices of this element
00221 }
00222 //-----------------------------------------------------------------------------
00223 //template <typename T>
00224 //Hexahedron<T>::Hexahedron ( Hexahedron<T> const &orig )
00225 //{}
00226 //-----------------------------------------------------------------------------
00227 template <typename T>
00228 Hexahedron<T>::~Hexahedron ()
00229 {}  
00230 //-----------------------------------------------------------------------------
00231 template <typename T>
00232 std::string Hexahedron<T>::StrInfo () const
00233 {
00234     std::stringstream ss;
00235     ss  << "FEM::Hexahedron<" << typeid(T).name() << ">:\n"
00236         << "\tDeformed - Undeformed Node 0: " << (*pU)[ids[0]] << " - " << (*pX)[ids[0]] << "\n"
00237         << "\tDeformed - Undeformed Node 1: " << (*pU)[ids[1]] << " - " << (*pX)[ids[1]] << "\n"
00238         << "\tDeformed - Undeformed Node 2: " << (*pU)[ids[2]] << " - " << (*pX)[ids[2]] << "\n"
00239         << "\tDeformed - Undeformed Node 3: " << (*pU)[ids[3]] << " - " << (*pX)[ids[3]] << "\n"
00240         << "\tDeformed - Undeformed Node 4: " << (*pU)[ids[4]] << " - " << (*pX)[ids[4]] << "\n"
00241         << "\tDeformed - Undeformed Node 5: " << (*pU)[ids[5]] << " - " << (*pX)[ids[5]] << "\n"
00242         << "\tDeformed - Undeformed Node 6: " << (*pU)[ids[6]] << " - " << (*pX)[ids[6]] << "\n"
00243         << "\tDeformed - Undeformed Node 7: " << (*pU)[ids[7]] << " - " << (*pX)[ids[7]] << "\n"
00244         << "\tDeformed - Undeformed Volume: " << CalDeformedVolume()  << " - " << Volume << "\n";
00245     return ss.str();
00246 }
00247 //-----------------------------------------------------------------------------
00248 //=============================================================================
00249 // Assignment Operator
00250 //-----------------------------------------------------------------------------
00251 //template <typename T>
00252 //Hexahedron<T> & Hexahedron<T>::operator= ( Hexahedron<T> const &orig )
00253 //{}
00254 //-----------------------------------------------------------------------------
00255 //=============================================================================
00256 // Get/Set Functions
00257 //-----------------------------------------------------------------------------
00258 template <typename T>
00259 Matrix3x3<T> const & Hexahedron<T>::GetStiffnessMatrix ( unsigned int n, unsigned int m ) const
00260 {
00261     assert( 0 <= n && n <= 7 );
00262     assert( 0 <= m && m <= 7 );
00263     return Ke[n][m];
00264 }   
00265 //-----------------------------------------------------------------------------
00266 //=============================================================================
00267 // Operations
00268 //-----------------------------------------------------------------------------
00269 template <typename T>
00270 void Hexahedron<T>::SetNode ( unsigned int i, unsigned int globalNodeNumber )
00271 {
00272     assert( 0 <= i && i <= 7 );
00273     ids[i] = globalNodeNumber;
00274 }   
00275 //-----------------------------------------------------------------------------
00276 //template <typename T>
00277 //void Hexahedron<T>::ResetToDeformedState ()
00278 //{
00279 //} 
00280 //-----------------------------------------------------------------------------
00281 template <typename T>
00282 void Hexahedron<T>::ResetToUndeformedState ()
00283 {
00284     (*pU)[ids[0]] = (*pX)[ids[0]];
00285     (*pU)[ids[1]] = (*pX)[ids[1]];
00286     (*pU)[ids[2]] = (*pX)[ids[2]];
00287     (*pU)[ids[3]] = (*pX)[ids[3]];
00288     (*pU)[ids[4]] = (*pX)[ids[4]];
00289     (*pU)[ids[5]] = (*pX)[ids[5]];
00290     (*pU)[ids[6]] = (*pX)[ids[6]];
00291     (*pU)[ids[7]] = (*pX)[ids[7]];
00292 }   
00293 //-----------------------------------------------------------------------------
00294 template <typename T>
00295 Vector3<T> * const Hexahedron<T>::DeformedNode ( unsigned int i )
00296 {
00297     assert( 0 <= i && i <= 7 );
00298     return &(*pU)[ids[i]];
00299 }   
00300 //-----------------------------------------------------------------------------
00301 template <typename T>
00302 Vector3<T> * const Hexahedron<T>::UndeformedNode ( unsigned int i )
00303 {
00304     assert( 0 <= i && i <= 7 );
00305     return &(*pX)[ids[i]];
00306 }
00307 //-----------------------------------------------------------------------------
00308 template <typename T>
00309 Vector3<T> Hexahedron<T>::ComputeDeformedPositionBasedOnCoordinates ( T xi, T eta, T zeta )
00310 {
00311     T s0 = 1 - xi;
00312     T s1 = 1 + xi;
00313     T t0 = 1 - eta;
00314     T t1 = 1 + eta;
00315     T r0 = 1 - zeta;
00316     T r1 = 1 + zeta;
00317 
00318     T N0 = s0 * t0 * r0;
00319     T N1 = s1 * t0 * r0;
00320     T N2 = s1 * t1 * r0;
00321     T N3 = s0 * t1 * r0;
00322     T N4 = s0 * t0 * r1;
00323     T N5 = s1 * t0 * r1;
00324     T N6 = s1 * t1 * r1;
00325     T N7 = s0 * t1 * r1;
00326 
00327     T x = 0.125 * ( (*pU)[ids[0]][0]*N0 + (*pU)[ids[1]][0]*N1 + (*pU)[ids[2]][0]*N2 + (*pU)[ids[3]][0]*N3 
00328                   + (*pU)[ids[4]][0]*N4 + (*pU)[ids[5]][0]*N5 + (*pU)[ids[6]][0]*N6 + (*pU)[ids[7]][0]*N7 );
00329     T y = 0.125 * ( (*pU)[ids[0]][1]*N0 + (*pU)[ids[1]][1]*N1 + (*pU)[ids[2]][1]*N2 + (*pU)[ids[3]][1]*N3 
00330                   + (*pU)[ids[4]][1]*N4 + (*pU)[ids[5]][1]*N5 + (*pU)[ids[6]][1]*N6 + (*pU)[ids[7]][1]*N7 );
00331     T z = 0.125 * ( (*pU)[ids[0]][2]*N0 + (*pU)[ids[1]][2]*N1 + (*pU)[ids[2]][2]*N2 + (*pU)[ids[3]][2]*N3 
00332                   + (*pU)[ids[4]][2]*N4 + (*pU)[ids[5]][2]*N5 + (*pU)[ids[6]][2]*N6 + (*pU)[ids[7]][2]*N7 );
00333 
00334     return Vector3<T>( x, y, z );
00335 }
00336 //-----------------------------------------------------------------------------
00337 template <typename T>
00338 Vector3<T> Hexahedron<T>::ComputeUndeformedPositionBasedOnCoordinates ( T xi, T eta, T zeta )
00339 {
00340     T s0 = 1 - xi;
00341     T s1 = 1 + xi;
00342     T t0 = 1 - eta;
00343     T t1 = 1 + eta;
00344     T r0 = 1 - zeta;
00345     T r1 = 1 + zeta;
00346 
00347     T N0 = s0 * t0 * r0;
00348     T N1 = s1 * t0 * r0;
00349     T N2 = s1 * t1 * r0;
00350     T N3 = s0 * t1 * r0;
00351     T N4 = s0 * t0 * r1;
00352     T N5 = s1 * t0 * r1;
00353     T N6 = s1 * t1 * r1;
00354     T N7 = s0 * t1 * r1;
00355 
00356     T x = 0.125 * ( (*pX)[ids[0]][0]*N0 + (*pX)[ids[1]][0]*N1 + (*pX)[ids[2]][0]*N2 + (*pX)[ids[3]][0]*N3 
00357                   + (*pX)[ids[4]][0]*N4 + (*pX)[ids[5]][0]*N5 + (*pX)[ids[6]][0]*N6 + (*pX)[ids[7]][0]*N7 );
00358     T y = 0.125 * ( (*pX)[ids[0]][1]*N0 + (*pX)[ids[1]][1]*N1 + (*pX)[ids[2]][1]*N2 + (*pX)[ids[3]][1]*N3 
00359                   + (*pX)[ids[4]][1]*N4 + (*pX)[ids[5]][1]*N5 + (*pX)[ids[6]][1]*N6 + (*pX)[ids[7]][1]*N7 );
00360     T z = 0.125 * ( (*pX)[ids[0]][2]*N0 + (*pX)[ids[1]][2]*N1 + (*pX)[ids[2]][2]*N2 + (*pX)[ids[3]][2]*N3 
00361                   + (*pX)[ids[4]][2]*N4 + (*pX)[ids[5]][2]*N5 + (*pX)[ids[6]][2]*N6 + (*pX)[ids[7]][2]*N7 );
00362 
00363     return Vector3<T>( x, y, z );
00364 }
00365 //-----------------------------------------------------------------------------
00373 template <typename T>
00374 int Hexahedron<T>::EstimateParametricCoords (
00375     T x, T y, T z,          
00376     T &xi, T &eta, T &zeta  
00377 )
00378 {
00379     // Using Newton's method
00380 
00381     // Initialize parametric coordinates
00382     xi = eta = zeta = 0.5;
00383     T px = xi;
00384     T py = eta;
00385     T pz = zeta;
00386     Vector3<T> C[4];
00387     //Vector3<T> Point;
00388     T weights[8];
00389     T derivs[24];
00390     bool bFoundAGoodOne = false;
00391 
00392     // Iteration loop
00393     for ( int iteration = 0; !bFoundAGoodOne && iteration < MAX_ITERATION; ++iteration ) {
00394         //Point = ComputeDeformedPositionBasedOnCoordinates( xi, eta, zeta );
00395         InterpolateShapeFunctions( xi, eta, zeta, weights );
00396         InterpolateShapeFunctionDerivatives( xi, eta, zeta, derivs );
00397 
00398         // Newton function
00399         //-------------------------------------------------
00400         for ( int i = 0; i < 4; ++i ) {
00401             C[i].Clear();   // clear data for matrix
00402         }
00403         for ( int p = 0; p < 8; ++p ) {
00404             C[0] += weights[p]    * (*pU)[ids[p]];
00405             C[1] += derivs[p    ] * (*pU)[ids[p]];
00406             C[2] += derivs[p + 8] * (*pU)[ids[p]];
00407             C[3] += derivs[p +16] * (*pU)[ids[p]];
00408         }
00409         C[0][0] -= x;
00410         C[0][1] -= y;
00411         C[0][2] -= z;
00412 
00413         // Compute determinants and find better estimation
00414         T det = Matrix3x3<T>(   C[1][0], C[2][0], C[3][0],
00415                                 C[1][1], C[2][1], C[3][1],
00416                                 C[1][2], C[2][2], C[3][2] ).GetDeterminant();
00417 
00418         if ( fabs( det ) < 1E-20 ) {
00419             return -1;  // couldn't find a good estimation
00420         }
00421 
00422         xi   = px - Matrix3x3<T>(   C[0][0], C[2][0], C[3][0],
00423                                     C[0][1], C[2][1], C[3][1],
00424                                     C[0][2], C[2][2], C[3][2] ).GetDeterminant() / det;
00425         eta  = py - Matrix3x3<T>(   C[1][0], C[0][0], C[3][0],
00426                                     C[1][1], C[0][1], C[3][1],
00427                                     C[1][2], C[0][2], C[3][2] ).GetDeterminant() / det;
00428         zeta = pz - Matrix3x3<T>(   C[1][0], C[2][0], C[0][0],
00429                                     C[1][1], C[2][1], C[0][1],
00430                                     C[1][2], C[2][2], C[0][2] ).GetDeterminant() / det;
00431         //-------------------------------------------------
00432 
00433         // Check for divergence
00434         if (    fabs(xi) > DIVERGENCE_THRESHOLD
00435             ||  fabs(eta) > DIVERGENCE_THRESHOLD
00436             ||  fabs(zeta) > DIVERGENCE_THRESHOLD )
00437         {
00438             return -2;  // failed to find a good estimation due to divergence
00439         }
00440 
00441         // If less than the error threshold, stop.
00442         if (    fabs(xi-px) < ERROR_THRESHOLD
00443             &&  fabs(eta-py) < ERROR_THRESHOLD
00444             &&  fabs(zeta-pz) < ERROR_THRESHOLD )
00445         {
00446             bFoundAGoodOne = true;
00447         }
00448         // Else, repeat the Newton function.
00449         else {
00450             px = xi;
00451             py = eta;
00452             pz = zeta;
00453         }
00454     }
00455 
00456     // If the max iteration is reached before a good estimation is found.
00457     if ( !bFoundAGoodOne ) {
00458         return -3;  // failed to find a good estimation before the max iteration is reached
00459     }
00460 
00461     // Check whether the estimated point is inside or outside the element
00462     //InterpolateShapeFunctions( xi, eta, zeta, weights );
00463     if (    NEG_BOUND <= xi   && xi   <= POS_BOUND
00464         &&  NEG_BOUND <= eta  && eta  <= POS_BOUND
00465         &&  NEG_BOUND <= zeta && zeta <= POS_BOUND )
00466     {
00467         return 1;   // the global point is inside the hexahedron.
00468     }
00469     else {
00470         return 0;   // the global point is outside the hexahedron.
00471     }
00472 }
00473 //-----------------------------------------------------------------------------
00474 template <typename T>
00475 T   Hexahedron<T>::CalDeformedVolume () const
00476 {
00477     std::cout << "Hexahedron<T>::CalDeformedVolume isn't implemented yet!!!\n";
00478     return 1;
00479 }   
00480 //-----------------------------------------------------------------------------
00481 template <typename T>
00482 T   Hexahedron<T>::CalUndeformedVolume ()
00483 {
00484     // Assume the undeformed hexahedron is a parallelepiped, then
00485     // Volume = AxB.C
00486     Vector3<T> crossProd = (((*pX)[ids[1]]-(*pX)[ids[0]])^((*pX)[ids[3]]-(*pX)[ids[0]]));
00487     Volume = (((*pX)[ids[1]]-(*pX)[ids[0]])^((*pX)[ids[3]]-(*pX)[ids[0]])) * ((*pX)[ids[4]]-(*pX)[ids[0]]);
00488     return Volume;
00489 }   
00490 //-----------------------------------------------------------------------------
00491 template <typename T>
00492 void Hexahedron<T>::UpdateStrainDisplacementMatrixElements ()
00493 {
00494     // Too many variables to be kept for updating
00495     // So the update is changed to instant computation and added into 
00496     // UpdateStiffnessMatrixElements.
00497 
00498     // compute the elements of B
00499     // which are Nn_dx, Nn_dy, and Nn_dz for n = 0...7
00500 
00501     // B = [ B0 B1 B2 B3 B4 B5 B6 B7 ]
00502     // where Bn (n = 0,1,2,3,4,5,6,7) are
00503     //      | bn  0  0 |
00504     //      |  0 cn  0 |
00505     // Bn = |  0  0 dn |
00506     //      | cn bn  0 |
00507     //      |  0 dn cn |
00508     //      | dn  0 bn |
00509     // where 
00510     // | bn |            | Nn_dxi   |
00511     // | cn | = J_n^{-1} | Nn_deta  |
00512     // | dn |            | Nn_dzeta |
00513 
00514     // PICK ONE OF THESE
00515     //UpdateStrainDisplacementMatrixElements_1PtGauss();
00516     //UpdateStrainDisplacementMatrixElements_2PtGauss();
00517 }
00518 //-----------------------------------------------------------------------------
00519 template <typename T>
00520 void Hexahedron<T>::UpdateStiffnessMatrixElements ()
00521 {
00522     // PICK ONE OF THESE
00523     //UpdateStiffnessMatrixElements_1PtGauss();
00524     UpdateStiffnessMatrixElements_2PtGauss();
00525 }
00526 //-----------------------------------------------------------------------------
00527 template <typename T>
00528 void Hexahedron<T>::UpdateStiffnessMatrixElements_1PtGauss ()
00529 {
00530     T b[8], c[8], d[8];
00531     Matrix3x3<T> J;
00532 
00533     // Calculate J and its inverse
00534     J = CalJacobian( g_1PtGauss_Der, 0 );
00535     T detJ = J.GetDeterminant();
00536     Matrix3x3<T> Jinv = J.GetInverse();
00537 
00538     // Calculate B[n]
00539     for ( int n=0; n<8; ++n ) {
00540         // | bn |            | Nn_dxi   |
00541         // | cn | = J^{-1} | Nn_deta  |
00542         // | dn |            | Nn_dzeta |
00543         b[n] = Jinv(0,0)*g_1PtGauss_Der[n] + Jinv(0,1)*g_1PtGauss_Der[n+8] + Jinv(0,2)*g_1PtGauss_Der[n+16];
00544         c[n] = Jinv(1,0)*g_1PtGauss_Der[n] + Jinv(1,1)*g_1PtGauss_Der[n+8] + Jinv(1,2)*g_1PtGauss_Der[n+16];
00545         d[n] = Jinv(2,0)*g_1PtGauss_Der[n] + Jinv(2,1)*g_1PtGauss_Der[n+8] + Jinv(2,2)*g_1PtGauss_Der[n+16];
00546     }
00547 
00548     // K^e_{nm} = Wi * Wj * Wk
00549     //   *
00550     //         | bn  0  0 cn  0 dn |
00551     //  Bn^T = |  0 cn  0 bn dn  0 |
00552     //         |  0  0 dn  0 cn bn |
00553     //   *
00554     //      | e f f 0 0 0 |
00555     //      | f e f 0 0 0 |
00556     //  E = | f f e 0 0 0 |
00557     //      | 0 0 0 g 0 0 |
00558     //      | 0 0 0 0 g 0 |
00559     //      | 0 0 0 0 0 g |
00560     //   *
00561     //       | bn  0  0 |
00562     //       |  0 cn  0 |
00563     //  Bn = |  0  0 dn |
00564     //       | cn bn  0 |
00565     //       |  0 dn cn |
00566     //       | dn  0 bn |
00567     //   *
00568     //  det(J)
00569     //
00570     // which is equivalent to
00571     //
00572     // K^e_{nm} = Wi * Wj * Wk *
00573     //    | bn  0  0 | | e f f | | bm  0  0 |   | cn  0 dn | | g 0 0 | | cm bm  0 |
00574     //    |  0 cn  0 |*| f e f |*|  0 cm  0 | + | bn dn  0 |*| 0 g 0 |*|  0 dm cm |
00575     //    |  0  0 dn | | f f e | |  0  0 dm |   |  0 cn bn | | 0 0 g | | dm  0 bm |
00576     //   * det(J)
00577     //  = Wi * Wj * Wk *
00578     //    | bn*e*bm + cn*g*cm + dn*g*dm      bn*f*cm + cn*g*bm           bn*f*dm + dn*g*bm      |
00579     //    |      cn*f*bm + bn*g*cm      cn*e*cm + bn*g*bm + dn*g*dm      cn*f*dm + dn*g*cm      |
00580     //    |      dn*f*bm + bn*g*dm           dn*f*cm + cn*g*dm      dn*e*dm + cn*g*cm + bn*g*bm |
00581     //   * det(J)
00582     T be[8] = { b[0]*Ee, b[1]*Ee, b[2]*Ee, b[3]*Ee, b[4]*Ee, b[5]*Ee, b[6]*Ee, b[7]*Ee };
00583     T bf[8] = { b[0]*Ef, b[1]*Ef, b[2]*Ef, b[3]*Ef, b[4]*Ef, b[5]*Ef, b[6]*Ef, b[7]*Ef };
00584     T bg[8] = { b[0]*Eg, b[1]*Eg, b[2]*Eg, b[3]*Eg, b[4]*Eg, b[5]*Eg, b[6]*Eg, b[7]*Eg };
00585 
00586     T ce[8] = { c[0]*Ee, c[1]*Ee, c[2]*Ee, c[3]*Ee, c[4]*Ee, c[5]*Ee, c[6]*Ee, c[7]*Ee };
00587     T cf[8] = { c[0]*Ef, c[1]*Ef, c[2]*Ef, c[3]*Ef, c[4]*Ef, c[5]*Ef, c[6]*Ef, c[7]*Ef };
00588     T cg[8] = { c[0]*Eg, c[1]*Eg, c[2]*Eg, c[3]*Eg, c[4]*Eg, c[5]*Eg, c[6]*Eg, c[7]*Eg };
00589 
00590     T de[8] = { d[0]*Ee, d[1]*Ee, d[2]*Ee, d[3]*Ee, d[4]*Ee, d[5]*Ee, d[6]*Ee, d[7]*Ee };
00591     T df[8] = { d[0]*Ef, d[1]*Ef, d[2]*Ef, d[3]*Ef, d[4]*Ef, d[5]*Ef, d[6]*Ef, d[7]*Ef };
00592     T dg[8] = { d[0]*Eg, d[1]*Eg, d[2]*Eg, d[3]*Eg, d[4]*Eg, d[5]*Eg, d[6]*Eg, d[7]*Eg };
00593 
00594     // Calculate K^e_{nm}
00595     for ( int n = 0; n < 8; ++n ) {
00596         for ( int m = 0; m < 8; ++m ) {
00597             if ( n <= m ) {
00598                 // 1st row
00599                 Ke[n][m](0,0) = be[n]*b[m] + cg[n]*c[m] + dg[n]*d[m];
00600                 Ke[n][m](0,1) = bf[n]*c[m] + cg[n]*b[m];
00601                 Ke[n][m](0,2) = bf[n]*d[m] + dg[n]*b[m];
00602                 // 2nd row
00603                 Ke[n][m](1,0) = cf[n]*b[m] + bg[n]*c[m];
00604                 Ke[n][m](1,1) = ce[n]*c[m] + bg[n]*b[m] + dg[n]*d[m];
00605                 Ke[n][m](1,2) = cf[n]*d[m] + dg[n]*c[m];
00606                 // 3rd row
00607                 Ke[n][m](2,0) = df[n]*b[m] + bg[n]*d[m];
00608                 Ke[n][m](2,1) = df[n]*c[m] + cg[n]*d[m];
00609                 Ke[n][m](2,2) = de[n]*d[m] + cg[n]*c[m] + bg[n]*b[m];
00610 
00611                 Ke[n][m] *= 8 * detJ;   // multiply by weights and detJ
00612             }
00613             // due to the symmetry of the linear tetrahedron's stiffness sub-matrices
00614             else {
00615                 Ke[n][m] = Ke[m][n].GetTranspose();
00616             }
00617         }
00618     }
00619 }
00620 //-----------------------------------------------------------------------------
00621 template <typename T>
00622 void Hexahedron<T>::UpdateStiffnessMatrixElements_2PtGauss ()
00623 {
00624     // Clear K^e_{nm}
00625     for ( int n = 0; n < 8; ++n ) {
00626         for ( int m = 0; m < 8; ++m ) {
00627             Ke[n][m].MakeZero();
00628         }
00629     }
00630 
00631     // 2-pt Gauss quadrature for 3D becomes 8 points
00632     T b[8], c[8], d[8];
00633 
00634     for ( int pt = 0, idx = 0; pt < 8; ++pt, idx+=24 ) {
00635 
00636         // Calculate J[n] and B[n]
00637         Matrix3x3<T> J = CalJacobian( g_2PtGauss_Der, pt );
00638         T detJ = J.GetDeterminant();
00639         Matrix3x3<T> Jinv = J.GetInverse();
00640 
00641         for ( int n=0, idx2=idx; n<8; ++n, ++idx2 ) {
00642             // | bn |            | Nn_dxi   |
00643             // | cn | = J^{-1} | Nn_deta  |
00644             // | dn |            | Nn_dzeta |
00645             b[n] = Jinv(0,0)*g_2PtGauss_Der[idx2] + Jinv(0,1)*g_2PtGauss_Der[idx2+8] + Jinv(0,2)*g_2PtGauss_Der[idx2+16];
00646             c[n] = Jinv(1,0)*g_2PtGauss_Der[idx2] + Jinv(1,1)*g_2PtGauss_Der[idx2+8] + Jinv(1,2)*g_2PtGauss_Der[idx2+16];
00647             d[n] = Jinv(2,0)*g_2PtGauss_Der[idx2] + Jinv(2,1)*g_2PtGauss_Der[idx2+8] + Jinv(2,2)*g_2PtGauss_Der[idx2+16];
00648         }
00649 
00650         // K^e_{nm} = Wi * Wj * Wk
00651         //   *
00652         //         | bn  0  0 cn  0 dn |
00653         //  Bn^T = |  0 cn  0 bn dn  0 |
00654         //         |  0  0 dn  0 cn bn |
00655         //   *
00656         //      | e f f 0 0 0 |
00657         //      | f e f 0 0 0 |
00658         //  E = | f f e 0 0 0 |
00659         //      | 0 0 0 g 0 0 |
00660         //      | 0 0 0 0 g 0 |
00661         //      | 0 0 0 0 0 g |
00662         //   *
00663         //       | bn  0  0 |
00664         //       |  0 cn  0 |
00665         //  Bn = |  0  0 dn |
00666         //       | cn bn  0 |
00667         //       |  0 dn cn |
00668         //       | dn  0 bn |
00669         //   *
00670         //  det(J)
00671         //
00672         // which is equivalent to
00673         //
00674         // K^e_{nm} = Wi * Wj * Wk *
00675         //    | bn  0  0 | | e f f | | bm  0  0 |   | cn  0 dn | | g 0 0 | | cm bm  0 |
00676         //    |  0 cn  0 |*| f e f |*|  0 cm  0 | + | bn dn  0 |*| 0 g 0 |*|  0 dm cm |
00677         //    |  0  0 dn | | f f e | |  0  0 dm |   |  0 cn bn | | 0 0 g | | dm  0 bm |
00678         //   * det(J)
00679         //  = Wi * Wj * Wk *
00680         //    | bn*e*bm + cn*g*cm + dn*g*dm      bn*f*cm + cn*g*bm           bn*f*dm + dn*g*bm      |
00681         //    |      cn*f*bm + bn*g*cm      cn*e*cm + bn*g*bm + dn*g*dm      cn*f*dm + dn*g*cm      |
00682         //    |      dn*f*bm + bn*g*dm           dn*f*cm + cn*g*dm      dn*e*dm + cn*g*cm + bn*g*bm |
00683         //   * det(J)
00684         T be[8] = { b[0]*Ee, b[1]*Ee, b[2]*Ee, b[3]*Ee, b[4]*Ee, b[5]*Ee, b[6]*Ee, b[7]*Ee };
00685         T bf[8] = { b[0]*Ef, b[1]*Ef, b[2]*Ef, b[3]*Ef, b[4]*Ef, b[5]*Ef, b[6]*Ef, b[7]*Ef };
00686         T bg[8] = { b[0]*Eg, b[1]*Eg, b[2]*Eg, b[3]*Eg, b[4]*Eg, b[5]*Eg, b[6]*Eg, b[7]*Eg };
00687 
00688         T ce[8] = { c[0]*Ee, c[1]*Ee, c[2]*Ee, c[3]*Ee, c[4]*Ee, c[5]*Ee, c[6]*Ee, c[7]*Ee };
00689         T cf[8] = { c[0]*Ef, c[1]*Ef, c[2]*Ef, c[3]*Ef, c[4]*Ef, c[5]*Ef, c[6]*Ef, c[7]*Ef };
00690         T cg[8] = { c[0]*Eg, c[1]*Eg, c[2]*Eg, c[3]*Eg, c[4]*Eg, c[5]*Eg, c[6]*Eg, c[7]*Eg };
00691 
00692         T de[8] = { d[0]*Ee, d[1]*Ee, d[2]*Ee, d[3]*Ee, d[4]*Ee, d[5]*Ee, d[6]*Ee, d[7]*Ee };
00693         T df[8] = { d[0]*Ef, d[1]*Ef, d[2]*Ef, d[3]*Ef, d[4]*Ef, d[5]*Ef, d[6]*Ef, d[7]*Ef };
00694         T dg[8] = { d[0]*Eg, d[1]*Eg, d[2]*Eg, d[3]*Eg, d[4]*Eg, d[5]*Eg, d[6]*Eg, d[7]*Eg };
00695 
00696         // Calculate K^e_{nm}
00697         for ( int n = 0; n < 8; ++n ) {
00698             for ( int m = 0; m < 8; ++m ) {
00699                 if ( n <= m ) {
00700                     // 1st row
00701                     Ke[n][m](0,0) += (be[n]*b[m] + cg[n]*c[m] + dg[n]*d[m]) * detJ;
00702                     Ke[n][m](0,1) += (bf[n]*c[m] + cg[n]*b[m]) * detJ;
00703                     Ke[n][m](0,2) += (bf[n]*d[m] + dg[n]*b[m]) * detJ;
00704                     // 2nd row
00705                     Ke[n][m](1,0) += (cf[n]*b[m] + bg[n]*c[m]) * detJ;
00706                     Ke[n][m](1,1) += (ce[n]*c[m] + bg[n]*b[m] + dg[n]*d[m]) * detJ;
00707                     Ke[n][m](1,2) += (cf[n]*d[m] + dg[n]*c[m]) * detJ;
00708                     // 3rd row
00709                     Ke[n][m](2,0) += (df[n]*b[m] + bg[n]*d[m]) * detJ;
00710                     Ke[n][m](2,1) += (df[n]*c[m] + cg[n]*d[m]) * detJ;
00711                     Ke[n][m](2,2) += (de[n]*d[m] + cg[n]*c[m] + bg[n]*b[m]) * detJ;
00712                 }
00713                 // due to the symmetry of the linear tetrahedron's stiffness sub-matrices
00714                 // will be done after this loop
00715             }
00716         }
00717     }
00718 
00719     // Calculate K^e_{nm} from symmetry
00720     for ( int n = 0; n < 8; ++n ) {
00721         for ( int m = 0; m < 8; ++m ) {
00722             if ( n <= m ) {
00723                 //i.e. Ke[n][m] *= 1*1*1;   // multiply by weights
00724             }
00725             // due to the symmetry of the linear tetrahedron's stiffness sub-matrices
00726             else {
00727                 Ke[n][m] = Ke[m][n].GetTranspose();
00728             }
00729         }
00730     }
00731 }
00732 
00733 //-----------------------------------------------------------------------------
00734 template <typename T>
00735 void Hexahedron<T>::InterpolateShapeFunctions (
00736     T xi,           
00737     T eta,          
00738     T zeta,         
00739     T weights[8]    
00740 )
00741 {
00742     T S = T(0.125);
00743     T a_0 = 1 - xi;  T b_0 = 1 - eta;  T c_0 = 1 - zeta;
00744     T a_1 = 1 + xi;  T b_1 = 1 + eta;  T c_1 = 1 + zeta;
00745 
00746     weights[0] = S * a_0 * b_0 * c_0;
00747     weights[1] = S * a_1 * b_0 * c_0;
00748     weights[2] = S * a_1 * b_1 * c_0;
00749     weights[3] = S * a_0 * b_1 * c_0;
00750     weights[4] = S * a_0 * b_0 * c_1;
00751     weights[5] = S * a_1 * b_0 * c_1;
00752     weights[6] = S * a_1 * b_1 * c_1;
00753     weights[7] = S * a_0 * b_1 * c_1;
00754 }
00755 
00756 //-----------------------------------------------------------------------------
00757 template <typename T>
00758 void Hexahedron<T>::InterpolateShapeFunctionDerivatives (
00759     T xi,           
00760     T eta,          
00761     T zeta,         
00762     T derivs[24]    
00763 )
00764 {
00765     T S = T(0.125);
00766     T a_0 = 1 - xi;  T b_0 = 1 - eta;  T c_0 = 1 - zeta;
00767     T a_1 = 1 + xi;  T b_1 = 1 + eta;  T c_1 = 1 + zeta;
00768 
00769     // N_0 to N_7 partial diff by xi
00770     derivs[ 0] = -S * b_0 * c_0;
00771     derivs[ 1] =  S * b_0 * c_0;
00772     derivs[ 2] =  S * b_1 * c_0;
00773     derivs[ 3] = -S * b_1 * c_0;
00774     derivs[ 4] = -S * b_0 * c_1;
00775     derivs[ 5] =  S * b_0 * c_1;
00776     derivs[ 6] =  S * b_1 * c_1;
00777     derivs[ 7] = -S * b_1 * c_1;
00778 
00779     // N_0 to N_7 partial diff by eta
00780     derivs[ 8] = -S * a_0 * c_0;
00781     derivs[ 9] = -S * a_1 * c_0;
00782     derivs[10] =  S * a_1 * c_0;
00783     derivs[11] =  S * a_0 * c_0;
00784     derivs[12] = -S * a_0 * c_1;
00785     derivs[13] = -S * a_1 * c_1;
00786     derivs[14] =  S * a_1 * c_1;
00787     derivs[15] =  S * a_0 * c_1;
00788     
00789     // N_0 to N_7 partial diff by zeta
00790     derivs[16] = -S * a_0 * b_0;
00791     derivs[17] = -S * a_1 * b_0;
00792     derivs[18] = -S * a_1 * b_1;
00793     derivs[19] = -S * a_0 * b_1;
00794     derivs[20] =  S * a_0 * b_0;
00795     derivs[21] =  S * a_1 * b_0;
00796     derivs[22] =  S * a_1 * b_1;
00797     derivs[23] =  S * a_0 * b_1;
00798 }
00799 //-----------------------------------------------------------------------------
00800 //=============================================================================
00801 
00802 
00803 
00804 
00805 //=============================================================================
00806 // OpenGL
00807 #if defined(__gl_h_) || defined(__GL_H__)
00808 //-----------------------------------------------------------------------------
00810 template <typename T>
00811 void Hexahedron<T>::Draw ()
00812 {
00813     glPushAttrib( GL_LINE_BIT );
00814 
00815     // Draw the undeformed element
00816     glLineWidth( 1 );
00817     //glPushMatrix();
00818     //glTranslatef( 0.5, 0.5, 0.5 );
00819     glBegin( GL_LINE_LOOP );
00820         glColor3f( 1.0f, 0.0f, 0.0f );
00821         glVertex3fv( (*pX)[ids[0]].GetDataFloat() );
00822         glVertex3fv( (*pX)[ids[1]].GetDataFloat() );
00823         glVertex3fv( (*pX)[ids[2]].GetDataFloat() );
00824         glVertex3fv( (*pX)[ids[3]].GetDataFloat() );
00825     glEnd();
00826     glBegin( GL_LINES );
00827         glColor3f( 0.0f, 1.0f, 0.0f );
00828         glVertex3fv( (*pX)[ids[0]].GetDataFloat() );
00829         glVertex3fv( (*pX)[ids[4]].GetDataFloat() );
00830         glVertex3fv( (*pX)[ids[1]].GetDataFloat() );
00831         glVertex3fv( (*pX)[ids[5]].GetDataFloat() );
00832         glVertex3fv( (*pX)[ids[2]].GetDataFloat() );
00833         glVertex3fv( (*pX)[ids[6]].GetDataFloat() );
00834         glVertex3fv( (*pX)[ids[3]].GetDataFloat() );
00835         glVertex3fv( (*pX)[ids[7]].GetDataFloat() );
00836     glEnd();
00837     glBegin( GL_LINE_LOOP );
00838         glColor3f( 0.0f, 0.0f, 1.0f );
00839         glVertex3fv( (*pX)[ids[4]].GetDataFloat() );
00840         glVertex3fv( (*pX)[ids[5]].GetDataFloat() );
00841         glVertex3fv( (*pX)[ids[6]].GetDataFloat() );
00842         glVertex3fv( (*pX)[ids[7]].GetDataFloat() );
00843     glEnd();
00844     //glPopMatrix();
00845 
00846     // Draw the deformed element
00847     glLineWidth( 3 );
00848     glBegin( GL_LINE_LOOP );
00849         glColor3f( 1.0f, 0.0f, 0.0f );
00850         glVertex3fv( (*pU)[ids[0]].GetDataFloat() );
00851         glVertex3fv( (*pU)[ids[1]].GetDataFloat() );
00852         glVertex3fv( (*pU)[ids[2]].GetDataFloat() );
00853         glVertex3fv( (*pU)[ids[3]].GetDataFloat() );
00854     glEnd();
00855     glBegin( GL_LINES );
00856         glColor3f( 0.0f, 1.0f, 0.0f );
00857         glVertex3fv( (*pU)[ids[0]].GetDataFloat() );
00858         glVertex3fv( (*pU)[ids[4]].GetDataFloat() );
00859         glVertex3fv( (*pU)[ids[1]].GetDataFloat() );
00860         glVertex3fv( (*pU)[ids[5]].GetDataFloat() );
00861         glVertex3fv( (*pU)[ids[2]].GetDataFloat() );
00862         glVertex3fv( (*pU)[ids[6]].GetDataFloat() );
00863         glVertex3fv( (*pU)[ids[3]].GetDataFloat() );
00864         glVertex3fv( (*pU)[ids[7]].GetDataFloat() );
00865     glEnd();
00866     glBegin( GL_LINE_LOOP );
00867         glColor3f( 0.0f, 0.0f, 1.0f );
00868         glVertex3fv( (*pU)[ids[4]].GetDataFloat() );
00869         glVertex3fv( (*pU)[ids[5]].GetDataFloat() );
00870         glVertex3fv( (*pU)[ids[6]].GetDataFloat() );
00871         glVertex3fv( (*pU)[ids[7]].GetDataFloat() );
00872     glEnd();
00873 
00874     glPopAttrib();
00875 }
00876 
00877 
00878 //-------------------------------------------------------------------
00879 template <typename T>
00880 void Hexahedron<T>::DrawUndeformedMesh ()
00881 {
00882     glPushAttrib( GL_LINE_BIT );
00883     // Draw the undeformed element
00884     glLineWidth( 1 );
00885     glBegin( GL_LINE_LOOP );
00886         glColor3f( 1.0f, 0.0f, 0.0f );
00887         glVertex3fv( (*pX)[ids[0]].GetDataFloat() );
00888         glVertex3fv( (*pX)[ids[1]].GetDataFloat() );
00889         glVertex3fv( (*pX)[ids[2]].GetDataFloat() );
00890         glVertex3fv( (*pX)[ids[3]].GetDataFloat() );
00891     glEnd();
00892     glBegin( GL_LINES );
00893         glColor3f( 0.0f, 1.0f, 0.0f );
00894         glVertex3fv( (*pX)[ids[0]].GetDataFloat() );
00895         glVertex3fv( (*pX)[ids[4]].GetDataFloat() );
00896         glVertex3fv( (*pX)[ids[1]].GetDataFloat() );
00897         glVertex3fv( (*pX)[ids[5]].GetDataFloat() );
00898         glVertex3fv( (*pX)[ids[2]].GetDataFloat() );
00899         glVertex3fv( (*pX)[ids[6]].GetDataFloat() );
00900         glVertex3fv( (*pX)[ids[3]].GetDataFloat() );
00901         glVertex3fv( (*pX)[ids[7]].GetDataFloat() );
00902     glEnd();
00903     glBegin( GL_LINE_LOOP );
00904         glColor3f( 0.0f, 0.0f, 1.0f );
00905         glVertex3fv( (*pX)[ids[4]].GetDataFloat() );
00906         glVertex3fv( (*pX)[ids[5]].GetDataFloat() );
00907         glVertex3fv( (*pX)[ids[6]].GetDataFloat() );
00908         glVertex3fv( (*pX)[ids[7]].GetDataFloat() );
00909     glEnd();
00910     glPopAttrib();
00911 }
00912 
00913 
00914 //-------------------------------------------------------------------
00916 template <typename T>
00917 void Hexahedron<T>::DrawDeformedMesh ()
00918 {
00919     glPushAttrib( GL_LINE_BIT );
00920     // Draw the deformed element
00921     glLineWidth( 1 );
00922     glBegin( GL_LINE_LOOP );
00923         glColor3f( 1.0f, 0.0f, 0.0f );
00924         glVertex3fv( (*pU)[ids[0]].GetDataFloat() );
00925         glVertex3fv( (*pU)[ids[1]].GetDataFloat() );
00926         glVertex3fv( (*pU)[ids[2]].GetDataFloat() );
00927         glVertex3fv( (*pU)[ids[3]].GetDataFloat() );
00928     glEnd();
00929     glBegin( GL_LINES );
00930         glColor3f( 0.0f, 1.0f, 0.0f );
00931         glVertex3fv( (*pU)[ids[0]].GetDataFloat() );
00932         glVertex3fv( (*pU)[ids[4]].GetDataFloat() );
00933         glVertex3fv( (*pU)[ids[1]].GetDataFloat() );
00934         glVertex3fv( (*pU)[ids[5]].GetDataFloat() );
00935         glVertex3fv( (*pU)[ids[2]].GetDataFloat() );
00936         glVertex3fv( (*pU)[ids[6]].GetDataFloat() );
00937         glVertex3fv( (*pU)[ids[3]].GetDataFloat() );
00938         glVertex3fv( (*pU)[ids[7]].GetDataFloat() );
00939     glEnd();
00940     glBegin( GL_LINE_LOOP );
00941         glColor3f( 0.0f, 0.0f, 1.0f );
00942         glVertex3fv( (*pU)[ids[4]].GetDataFloat() );
00943         glVertex3fv( (*pU)[ids[5]].GetDataFloat() );
00944         glVertex3fv( (*pU)[ids[6]].GetDataFloat() );
00945         glVertex3fv( (*pU)[ids[7]].GetDataFloat() );
00946     glEnd();
00947     glPopAttrib();
00948 }
00949 //-----------------------------------------------------------------------------
00950 #endif // OpenGL
00951 //=============================================================================
00952 //-----------------------------------------------------------------------------
00953 //=============================================================================
00954 END_NAMESPACE_TAPs__FEM
00955 //34567890123456789012345678901234567890123456789012345678901234567890123456789
00956 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines